Найти - Пользователи
Полная версия: Что делать?
Начало » Python для новичков » Что делать?
1 2
Vladislavkot2
Что не так?
Вот Код:
 # бот для выполнения упражнений    
# сайт: gramotei.cerm.ru  
 
import requests
import json
import collections
 
 
#номер упражнения и куки
rule_id = "40464"
cookie  = "PHPSESSID=d0b27d53fb2c53c386e920c64fe1f5d"
 
#заголовки пакетов
headers = {"Host": "gramotei.cerm.ru",
           "User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0",
           "Accept": "*/*",
           "Accept-Language": "ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3",
           "X-Requested-With": "XMLHttpRequest",
           "DNT": "1",
           "Referer": "http://gramotei.cerm.ru/student/train/"+rule_id,
           "Cookie": cookie,
           "Connection": "keep-alive"}
 
headers2 = headers
headers2["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8"
 
y = 0
while y < 5:
    #получение заданий
    r = requests.post("http://gramotei.cerm.ru/student/train/"+rule_id+"/new", headers = headers)
    f = r.json()
 
    lol = []
    n = 8
 
    for lts in f["word"]:
        SaveDate = '{"id":'+json.dumps(lts["id"])+',"rule_id":'+json.dumps(lts["rule"])+',"status":"correct"}'
        lol.append(json.loads(SaveDate, object_pairs_hook=collections.OrderedDict))
 
        if(n <= 0):
            data = "data="+json.dumps(lol)
            print(data)
 
            #отправка предварительного отчета чезез GET
            url = "http://gramotei.cerm.ru/App/Teacher/ajax.php?save_words=ok&ex_id="+rule_id+"&saving=0&data="+json.dumps(lol)
            SaveGet = requests.get(url, headers = headers)
            print(SaveGet.status_code, " ", SaveGet.text)
 
            #отправка отчета чезез POST
            SavePOST = requests.post("http://gramotei.cerm.ru/student/saveResult/"+rule_id, headers = headers2, data = data)
            print(SavePOST.status_code, " ", SavePOST.text)
        else:
            n=n-1

Вот ошибка:
== RESTART: CUsers/User/AppData/Local/Programs/Python/Python35/1337228.py ==
Traceback (most recent call last):
File “CUsers/User/AppData/Local/Programs/Python/Python35/1337228.py”, line 31, in <module>
f = r.json()
File “C:\Users\User\AppData\Local\Programs\Python\Python35\lib\site-packages\requests\models.py”, line 892, in json
return complexjson.loads(self.text, **kwargs)
File “C:\Users\User\AppData\Local\Programs\Python\Python35\lib\json\__init__.py”, line 319, in loads
return _default_decoder.decode(s)
File “C:\Users\User\AppData\Local\Programs\Python\Python35\lib\json\decoder.py”, line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File “C:\Users\User\AppData\Local\Programs\Python\Python35\lib\json\decoder.py”, line 357, in raw_decode
raise JSONDecodeError(“Expecting value”, s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
JOHN_16
НУ вам вернулся видимо не json, сделайте хоть принт содержимого что бы понять что там
Vladislavkot2
JOHN_16
Принт какого содержимого? Кода или что?
Vladislavkot2
Вот видос сюда залить не могу
https://yadi.sk/i/e4K7TeEs3SninQ
papuas
Vladislavkot2
r = requests.post("http://gramotei.cerm.ru/student/train/“+rule_id+”/new", headers = headers)
f = r.json()
print(r.text) вместо .json()
Vladislavkot2
теперь вот что
 ==== RESTART: C:\Users\User\AppData\Local\Programs\Python\Python35\sos.py ====
Traceback (most recent call last):
  File "C:\Users\User\AppData\Local\Programs\Python\Python35\sos.py", line 31, in <module>
    f = r. print(r.text)
AttributeError: 'Response' object has no attribute 'print'
Vladislavkot2
 ==== RESTART: C:\Users\User\AppData\Local\Programs\Python\Python35\sos.py ====
Traceback (most recent call last):
  File "C:\Users\User\AppData\Local\Programs\Python\Python35\sos.py", line 31, in <module>
    f = r. print(r.text)
AttributeError: 'Response' object has no attribute 'print'
JOHN_16
print(r.text)
просто такую строчку оставьте
Vladislavkot2
теперь вот:
 ==== RESTART: C:\Users\User\AppData\Local\Programs\Python\Python35\sos.py ====
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /student/train/“+rule_id+”/new was not found on this server.</p>
<hr>
<address>Apache/2.2.22 (Debian) Server at gramotei.cerm.ru Port 80</address>
</body></html>
Traceback (most recent call last):
  File "C:\Users\User\AppData\Local\Programs\Python\Python35\sos.py", line 35, in <module>
    for lts in f["words"]:
TypeError: 'NoneType' object is not subscriptable
>>> 
JOHN_16
Vladislavkot2
нуу а теперь подумайте сами - что в том что вы написали явно не так?
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB