I wrote this to try to enter the forum (phpBB3).
import urllib2, re import urllib, re logindata = urllib.urlencode({'username': 'x', 'password': 'y'}) page = urllib.urlopen("http://www.woarl.com/board/ucp.php?mode=login"[logindata]) output = page.read()
However, when I run it, it comes,
Traceback (most recent call last): File "C:/Users/Mike/Documents/python/test urllib2", line 4, in <module> page = urllib.urlopen("http://www.woarl.com/board/ucp.php?mode=login"[logindata]) TypeError: string indices must be integers
any ideas on how to solve this?
change
adding a comma between the line and the data gives this error instead
Traceback (most recent call last): File "C:/Users/Mike/Documents/python/test urllib2", line 4, in <module> page = urllib.urlopen("http://www.woarl.com/board/ucp.php?mode=login",[logindata]) File "C:\Python25\lib\urllib.py", line 84, in urlopen return opener.open(url, data) File "C:\Python25\lib\urllib.py", line 192, in open return getattr(self, name)(url, data) File "C:\Python25\lib\urllib.py", line 327, in open_http h.send(data) File "C:\Python25\lib\httplib.py", line 711, in send self.sock.sendall(str) File "<string>", line 1, in sendall TypeError: sendall() argument 1 must be string or read-only buffer, not list
edit2
I changed the code it was from
import urllib2, re import urllib, re logindata = urllib.urlencode({'username': 'x', 'password': 'y'}) page = urllib2.urlopen("http://www.woarl.com/board/ucp.php?mode=login", logindata) output = page.read()
This does not cause any error messages, it just gives 3 empty lines. This is because I am trying to read from the login page, which disappears after the login. If so, how can I get it to display the index that should appear after logging in.