Мой код:
import urllib.request, urllib.parse, urllib.error
def login():
url = 'http://rsbot.lt/news.php'
values = {'user_name' : 'Name',
'user_pass' : 'Password' }
data = urllib.parse.urlencode(values)
req = urllib.request.Request(url, data)
response = urllib.request.urlopen(req)
return response.read()
login()
Моя ошибка:
Traceback (most recent call last):
File "C:\Users\Myrez\Desktop\test.py", line 13, in <module>
login()
File "C:\Users\Myrez\Desktop\test.py", line 10, in login
response = urllib.request.urlopen(req)
File "C:\Python32\lib\urllib\request.py", line 138, in urlopen
return opener.open(url, data, timeout)
File "C:\Python32\lib\urllib\request.py", line 367, in open
req = meth(req)
File "C:\Python32\lib\urllib\request.py", line 1066, in do_request_
raise TypeError("POST data should be bytes"
TypeError: POST data should be bytes or an iterable of bytes. It cannot be str.
Я пытался кодировать, но это не помогло.