I'm having issues with the following code, and no knowledge of how to resolve my issues:
import urllib import http.cookiejar username = input("Username: ") password = input("Password: ") cookiejar = http.cookiejar.LWPCookieJar() opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(http.cookiejar)) opener.addheaders = [("User-agent","Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.100 Safari/534.30")] form = { "username" : username, "password" : password } encoded_form = urllib.parse.urlencode(form) request = urllib.request.urlopen("http://neopets.com/login/", encoded_form) webpage = opener.open(request) contents = page.read() if("logout" in contents): print("Logged In!") else: print("Login Failed")
Traceback (most recent call last):
File "C:/Users/John/Desktop/Python/Pet", line 13, in <module>
request = urllib.request.urlopen("http://neopets.com/login/", encoded_form)
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 364, in open
req = meth(req)
File "C:\Python32\lib\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.
Thank-you for your help!
Edited by OrangeWeapons, 22 June 2011 - 05:41 PM.