urlencode für POST "data should be bytes"
Verfasst: Montag 3. Oktober 2011, 16:14
Hey,
ich versuche mich seit einer Weile in Python, aber hier komme ich nicht weiter:
Also möchte mich über einen Python Script (später mal automatisch) dort anmelden, es kommt aber immer folgende Fehlermeldung:
Vielen Dank
ich versuche mich seit einer Weile in Python, aber hier komme ich nicht weiter:
Code: Alles auswählen
import urllib.request, urllib.parse
username = input("username: ")
password = input("password: ")
dc = {"username":username, "password":password}
data = urllib.parse.urlencode(dc)
u = urllib.request.urlopen("https://login.rz.ruhr-uni-bochum.de/cgi-bin/laklogin", data)
li = u.readlines()
u.close()
for e in li:
print(e)
Also so wie mir das jetzt erscheint ist urllib.parse.urlencode wohl hier nicht die richtige Wahl, oder ich muss noch etwas dazwischen schieben, aber was?username: name
password: pw
Traceback (most recent call last):
File "/home/kim/Python/rubi.py", line 9, in <module>
u = urllib.request.urlopen("https://login.rz.ruhr-uni-bochum.de/cgi-bin/laklogin", data)
File "/usr/lib64/python3.2/urllib/request.py", line 138, in urlopen
return opener.open(url, data, timeout)
File "/usr/lib64/python3.2/urllib/request.py", line 364, in open
req = meth(req)
File "/usr/lib64/python3.2/urllib/request.py", line 1052, 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.
Vielen Dank