Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #NON AUTH VERSION
- mydata=urllib.urlencode(mydata)
- path='complete path to script.php'
- req=urllib2.Request(path, mydata)
- req.add_header("Content-type", "application/x-www-form-urlencoded")
- try:
- page=urllib2.urlopen(req)
- except HTTPError, e:
- print 'The server couldn\'t fulfill the request.'
- print 'Error code: ', e.code
- except URLError, e:
- print e.reason
- print page
- #AUTH VERSION
- realm = 'None'
- url = 'complete path to script.php
- user = 'my user'
- passwd = 'my password ¿md5 encoded, or not?'
- data = mydata
- # create auth handler, build opener
- auth_handler = urllib2.HTTPBasicAuthHandler()
- auth_handler.add_password(realm=realm,
- uri=url,
- user=user,
- passwd=passwd)
- opener = urllib2.build_opener(auth_handler)
- # use opener to open the URL
- file_handle = opener.open(url, urllib.urlencode(data))
- # print response
- print file_handle.read()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement