473,799 Members | 3,084 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

sending commands in body of HTTP with urllib2

Hi,
Im trying to implement the logic from
http://www.hypothetic.org/docs/msn/g...onnections.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. 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.ProxyHa ndler({"http" : \
"http://%(host)s:%(port )d" % proxy_info})
opener = urllib2.build_o pener(proxy_sup port, urllib2.HTTPHan dler)

user_pass = base64.encodest ring('%s:%s' %
(urllib.unquote (USER),urllib.u nquote(PASS)))
authheader = "Basic %s" % user_pass

opener.addheade rs = [('Accept-Language','en-us'),
('Accept-Encoding','gzip , deflate'),
('Host','gatewa y.messenger.hot mail.com'),
('Proxy-Connection','Ke ep-Alive'),
('Connection',' Keep-Alive'),
('Pragma','no-cache'),
('Content-Type','applicat ion/x-msn-messenger'),
('User-agent','MSMSGS' ),
('Accept','*/*'),
('Proxy-authorization', authheader)]

# install it
urllib2.install _opener(opener)

# use it
url =
'http://gateway.messeng er.hotmail.com/gateway/gateway.dll?Act ion=open&Server =NS&IP=messenge r.hotmail.com'
values = 'VER 5 MSNP8 CVR0'

f = urllib2.urlopen (url,values)
print f.headers
print f.read()

Thanks for any help!
Jan 3 '08 #1
0 1270

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3965
by: Matthew Wilson | last post by:
I am writing a script to check on my router's external IP address. My ISP refreshes my IP very often and I use dyndns for the hostname for my computer. My Netgear mr814 router has a webserver that uses HTTP basic authorization. My script uses urllib2 to connect to the router and read the html page with the current external IP address. This is the function I wrote to lookup the router's external IP: def mr814(router_user,...
2
4343
by: OvErboRed | last post by:
Hi, I'm trying to determine whether a given URL exists. I'm new to Python but I think that urllib is the tool for the job. However, if I give it a non-existent file, it simply returns the 404 page. Aside from grepping this for '404', is there a better way to do this? (Preferrably, there is a solution that can be applied to both HTTP and FTP.) Thanks in advance.
7
9292
by: Michael Foord | last post by:
#!/usr/bin/python -u # 15-09-04 # v1.0.0 # auth_example.py # A simple script manually demonstrating basic authentication. # Copyright Michael Foord # Free to use, modify and relicense. # No warranty express or implied for the accuracy, fitness to purpose
4
8455
by: Dekaritae | last post by:
I have a script that I've written in Perl that retrieves files generated from a template. It works decently enough, but I'd like to rewrite it in Python (Perl was just a detour; it was originally Sed). Was wondering what the closest thing to what I'm using now in Perl (LWP::UserAgent and HTTP::Request:Common) is in Python. The main bit of my code is fairly simple. my($ua) = LWP::UserAgent->new; my $req = GET "$uri";
3
3192
by: John Reese | last post by:
Hello there. I've run into some missing functionality with HTTP Digest authentication in the 2.3 library and I was wondering if I'm just missing something. Missing functionality the first: urllib2 1a. You can add "handlers" to your opener indicating that you want to use HTTP Digest auth. This is nice way to handle it, but I don't see any way to use a custom verb in your URLOpener -- it always uses either GET or POST depending on...
2
3097
by: itay_k | last post by:
Hi, I want to send a cookie on some http request (with urllib2), so I created a Cookie but I cant associate it with CookieJar object. for example: import Cookie import cookielib, urllib2
2
3029
by: jabdulius | last post by:
Hi all, I'm trying to send a page using Perl via the WCTP protocol. For some reason, I cannot connect to the host "wctp.att.net/WCTP" (or any host for that matter). I figure it must be some server configuration that I need to set. I don't think it's a port problem b/c I'm able to send a page via WCTP using the same port using a stand-alone app. Anyhow, here's the code I'm using: sub send_wctp_old{ #my $url =...
0
1271
by: Jonas Galvez | last post by:
Try: import re import urllib2 url = 'http://www.google.com/search?num=20&hl=en&q=ipod&btnG=Search' user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)' headers = {'User-Agent' : user_agent} req = urllib2.Request(url, None, headers) file_source=open("google_source.txt", 'w') file_source.write(urllib2.urlopen(req).read())
2
3921
by: silk.odyssey | last post by:
I am getting the following error trying to download an html page using urllib2. urllib2.HTTPError: HTTP Error 204: NoContent The url is of this type: http://www.amazon.com/gp/offer-listing/B000KJX3A0%3FSubscriptionId%3D183VXJS74KNQ89D0NRR2%26tag%3Dws%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3DB000KJX3A0 I can open it in my browser without problems.Any ideas on a solution?
0
9538
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10473
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10219
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10025
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9068
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7563
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6804
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5461
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5584
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.