sending commands in body of HTTP with urllib2

Astan Chee stanc at al.com.au
Thu Jan 3 03:42:51 EST 2008


Astan Chee wrote:
> Hi,
> Im trying to implement the logic from 
> http://www.hypothetic.org/docs/msn/general/http_connections.php to a 
> simple python code using urllib2 and some parts of urllib. Im behind a 
> http proxy that requires authentication that is why Im using urllib2. Im 
> asking for help on how to send commands in a body of a HTTP before 
> requesting for response. What am I doing wrong? I only get the response 
> from the server but my commands never seem to be acknowledged or 
> properly handled. 
>   
I've tried a httplib implementation for it, and now it keeps giving me 
an Error 400 (bad request) / Invalid header name as a response. What am 
I doing wrong? is the server depreciated? or not working like the 
document describes it? Thanks again for any help. Below is my code


import httplib
import base64
import urllib

USER='user'
PASS='pass'
url = 
'http://gateway.messenger.hotmail.com/gateway/gateway.dll?Action=open&Server=NS&IP=messenger.hotmail.com'

values = 'VER 5 MSNP8 CVR0\r\n'
user_pass = base64.encodestring('%s:%s' % 
(urllib.unquote(USER),urllib.unquote(PASS)))
authheader =  "Basic %s" % user_pass
proxy_authorization='Proxy-authorization: Basic '+user_pass+'\r\n'

conn = httplib.HTTPConnection("proxy.com.au", 8080)
conn.connect()
conn.putrequest("POST", url)
conn.putheader('Accept','*/*')
conn.putheader('Accept-Language','en-us')
conn.putheader('Accept-Encoding','gzip, deflate')
conn.putheader('User-agent','MSMSGS')
conn.putheader('Host','gateway.messenger.hotmail.com')
conn.putheader('Proxy-Connection','Keep-Alive')
conn.putheader('Pragma','no-cache')
conn.putheader('Content-Type','application/x-msn-messenger')
conn.putheader('content-length',str(len(values)))
conn.putheader('Proxy-authorization',authheader)
conn.endheaders()
conn.send(values)
r = conn.getresponse()
print r.status, r.reason
print r.msg
print r.read()
       




More information about the Python-list mailing list