Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.python
sending commands in body of HTTP with urllib2
Astan Chee
1/3/2008 7:19:00 AM
Hi,
Im trying to implement the logic from
http://www.hypothetic.org/docs/msn/general/http_conne...
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. Below is my code:
import urllib2
import base64
import urllib
USER='user'
PASS='pass'
proxy_info = {'host' : "proxy.com.au",'port' : 8080}
# build a new opener that uses a proxy requiring authorization
proxy_support = urllib2.ProxyHandler({"http" : "http://%(host)s:%(port)d" % proxy_info})
opener = urllib2.build_opener(proxy_support, urllib2.HTTPHandler)
user_pass = base64.encodestring('%s:%s' %
(urllib.unquote(USER),urllib.unquote(PASS)))
authheader = "Basic %s" % user_pass
opener.addheaders = [('Accept-Language','en-us'),
('Accept-Encoding','gzip, deflate'),
('Host','gateway.messenger.hotmail.com'),
('Proxy-Connection','Keep-Alive'),
('Connection','Keep-Alive'),
('Pragma','no-cache'),
('Content-Type','application/x-msn-messenger'),
('User-agent','MSMSGS'),
('Accept','*/*'),
('Proxy-authorization',authheader)]
# install it
urllib2.install_opener(opener)
# use it
url =
'
http://gateway.messenger.hotmail.com/gateway/gateway.dll?Action=open&Server=NS&IP=messenger.hotmai...
values = 'VER 5 MSNP8 CVR0'
f = urllib2.urlopen(url,values)
print f.headers
print f.read()
Thanks for any help!
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
sending commands in body of HTTP with urllib2
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password