473,480 Members | 1,852 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

ClientCookie problem - Difference between 'post' on the local networkand the internet

I am using ClientCookie for login on to servers and browsing them as
authenticated users.

I kept getting "HTTP Error 400: Bad Request" errors when submitting my
forms. So I boiled it down to a simple example.

When I try to use ClientCookie.urlopen() on my private network with ip
numbers like "http://localhost:8081/test_site/logged_in", it works fine.

If I try to call the same site through the Internet, with a url like:
http://www.mxm.dk/test_site/logged_in I get the 400 message. But only
when using "post". 'get' works fine :-s

On the Internet I go out through a gateway, so my external IP is
different than my internal.

I assume that it causes an url mismatch somewhere. With my local ip
being set in some header by urlopener, and the server expecting the
remote ip.

But I have no idea as to how I can avoid it? Any takers?
#########################################

import ClientCookie, urllib

req = ClientCookie.Request
urlopen = ClientCookie.urlopen

def login(came_from, login_form):
data = {
'came_from' : came_from,
'__ac_name' : name,
'__ac_password' : password,
'__ac_persistent' : '1',
'submit' : 'Log ind',
}
encoded_data = urllib.urlencode(data)

request = req(login_form, encoded_data)
response = urlopen(request)
content = response.read()
return content

# This works
came_from = 'http://localhost:8081/test_site/request_tester'
login_form = "http://localhost:8081/test_site/logged_in"
print login(came_from, login_form)

# This results in "HTTP Error 400: Bad Request"
came_from = 'http://www.mxm.dk/test_site/request_tester'
login_form = "http://www.mxm.dk/test_site/logged_in"
print login(came_from, login_form)

############################################
# traceback from the last call to login()

Traceback (most recent call last):
File "E:\zopes\test_site\PRODUCTS\MXMPRO~1\z.py", line 35, in ?
print login(came_from, login_form)
File "E:\zopes\test_site\PRODUCTS\MXMPRO~1\z.py", line 22, in login
response = urlopen(request)
File
"G:\uninstalled\Python\ClientCookie-1.0.0a\ClientCookie\_urllib2_support.py",
line 715, in urlopen
return _opener.open(url, data)
File
"G:\uninstalled\Python\ClientCookie-1.0.0a\ClientCookie\_Opener.py",
line 125, in open
response = meth(req, response)
File
"G:\uninstalled\Python\ClientCookie-1.0.0a\ClientCookie\_urllib2_support.py",
line 387, in http_response
response = self.parent.error(
File
"G:\uninstalled\Python\ClientCookie-1.0.0a\ClientCookie\_Opener.py",
line 189, in error
return apply(self._call_chain, args)
File "C:\pytyons\Python23\lib\urllib2.py", line 306, in _call_chain
result = func(*args)
File "C:\pytyons\Python23\lib\urllib2.py", line 412, in
http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 400: Bad Request
--

hilsen/regards Max M, Denmark

http://www.mxm.dk/
IT's Mad Science
Jul 18 '05 #1
5 1773
On Fri, 22 Oct 2004 13:39:05 +0200, Max M <ma**@mxm.dk> wrote:
I am using ClientCookie for login on to servers and browsing them as
authenticated users.

I kept getting "HTTP Error 400: Bad Request" errors when submitting my
forms. So I boiled it down to a simple example.

When I try to use ClientCookie.urlopen() on my private network with ip
numbers like "http://localhost:8081/test_site/logged_in", it works fine.

If I try to call the same site through the Internet, with a url like:
http://www.mxm.dk/test_site/logged_in I get the 400 message. But only
when using "post". 'get' works fine :-s

Are you using Version 1.0.0a ?
There is a bug (well actually a bug in urllib2 - but it amoutns to the
same thing) that is fixed in CVS. Either use CVS or go back to 0.4
whatever which is the latest stable version.

Regards,

Fuzzy
On the Internet I go out through a gateway, so my external IP is
different than my internal.

I assume that it causes an url mismatch somewhere. With my local ip
being set in some header by urlopener, and the server expecting the
remote ip.

But I have no idea as to how I can avoid it? Any takers?
#########################################

import ClientCookie, urllib

req = ClientCookie.Request
urlopen = ClientCookie.urlopen

def login(came_from, login_form):
data = {
'came_from' : came_from,
'__ac_name' : name,
'__ac_password' : password,
'__ac_persistent' : '1',
'submit' : 'Log ind',
}
encoded_data = urllib.urlencode(data)

request = req(login_form, encoded_data)
response = urlopen(request)
content = response.read()
return content

# This works
came_from = 'http://localhost:8081/test_site/request_tester'
login_form = "http://localhost:8081/test_site/logged_in"
print login(came_from, login_form)

# This results in "HTTP Error 400: Bad Request"
came_from = 'http://www.mxm.dk/test_site/request_tester'
login_form = "http://www.mxm.dk/test_site/logged_in"
print login(came_from, login_form)

############################################
# traceback from the last call to login()

Traceback (most recent call last):
File "E:\zopes\test_site\PRODUCTS\MXMPRO~1\z.py", line 35, in ?
print login(came_from, login_form)
File "E:\zopes\test_site\PRODUCTS\MXMPRO~1\z.py", line 22, in login
response = urlopen(request)
File
"G:\uninstalled\Python\ClientCookie-1.0.0a\ClientCookie\_urllib2_support.py",
line 715, in urlopen
return _opener.open(url, data)
File
"G:\uninstalled\Python\ClientCookie-1.0.0a\ClientCookie\_Opener.py",
line 125, in open
response = meth(req, response)
File
"G:\uninstalled\Python\ClientCookie-1.0.0a\ClientCookie\_urllib2_support.py",
line 387, in http_response
response = self.parent.error(
File
"G:\uninstalled\Python\ClientCookie-1.0.0a\ClientCookie\_Opener.py",
line 189, in error
return apply(self._call_chain, args)
File "C:\pytyons\Python23\lib\urllib2.py", line 306, in _call_chain
result = func(*args)
File "C:\pytyons\Python23\lib\urllib2.py", line 412, in
http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 400: Bad Request


Jul 18 '05 #2
Fuzzyman wrote:
On Fri, 22 Oct 2004 13:39:05 +0200, Max M <ma**@mxm.dk> wrote: Are you using Version 1.0.0a ?
Yes
There is a bug (well actually a bug in urllib2 - but it amoutns to the
same thing) that is fixed in CVS. Either use CVS or go back to 0.4
whatever which is the latest stable version.


argh! Well that was a day of my life wasted :-( Well at least *this* day
was saved. Thank you.

It's one of the damnest problems with programming.

Either you write a module like ClientCookie yourself. Then you can find
bugs rather easily. But it takes so long to work out the special cases.

Or you can use an existing library. But if that has a bug, or is poorly
documented, you need to understand the library pretty well to bug fix
it. Leaving you esssentially in the hands of the author.

I find that moments like these are among the most frustrating in
programming.

Unfurtunately there is no easy way out, but some of the best stuff I
have seen to solve these kind of documentation problems, is the doctest
based code in Zope 3.

This approach to testing makes their code *really* easy to understand.

--

hilsen/regards Max M, Denmark

http://www.mxm.dk/
IT's Mad Science
Jul 18 '05 #3
Fuzzyman wrote:
Are you using Version 1.0.0a ?
There is a bug (well actually a bug in urllib2 - but it amoutns to the
same thing) that is fixed in CVS. Either use CVS or go back to 0.4
whatever which is the latest stable version.

I cannot seem to find a cvs repository for ClientCookie or wwwsearch
anywhere. Or do you mean that I should get urllib2 from cvs?
--

hilsen/regards Max M, Denmark

http://www.mxm.dk/
IT's Mad Science
Jul 18 '05 #4
Max M <ma**@mxm.dk> wrote in message news:<41**************@mxm.dk>...
Fuzzyman wrote:
Are you using Version 1.0.0a ?
There is a bug (well actually a bug in urllib2 - but it amoutns to the
same thing) that is fixed in CVS. Either use CVS or go back to 0.4
whatever which is the latest stable version.

I cannot seem to find a cvs repository for ClientCookie or wwwsearch
anywhere. Or do you mean that I should get urllib2 from cvs?


You're right.. I can't find it either. At least it's not on
sourceforge anyway..
John J Lee is the author of the module and he usually hangs around on
the wwwsearch mailing list (and sometimes here). When I reported the
bug to him a while ago he said he has fixed it in CVS. I just went
back to using 0.9 which I'm not sure is now easily available....

If you want I can mail that one to you.
Mail me on fuzzyman AT voidspace DOT org DOT uk and I'll see if I can
dig it out.

Regards,

Fuzzy

http://www.voidspace.org.uk/atlantib...thonutils.html
Jul 18 '05 #5
On Fri, 22 Oct 2004, Max M wrote:
I kept getting "HTTP Error 400: Bad Request" errors when submitting my
forms. So I boiled it down to a simple example. [...] #########################################

import ClientCookie, urllib [...] urllib2.HTTPError: HTTP Error 400: Bad Request


I'm not certain this is the problem fuzzyman refers to.

Thanks for sample, but I get NameError instead, so your script needs
fixing before I can easily investigate:

Traceback (most recent call last):
File "/home/john/bin/tst.py", line 59, in ?
print login(came_from, login_form)
File "/home/john/bin/tst.py", line 42, in login
data = {
NameError: global name 'name' is not defined
John
Jul 18 '05 #6

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

Similar topics

28
2318
by: Mark Carter | last post by:
I am using Windows 98, python 2.3, ClientCookie 0.4.3a. When I do: import ClientCookie import os c = ClientCookie.MSIECookieJar(delayload=1) c.load_from_registry() I get the response:...
0
1638
by: Grant Edwards | last post by:
In the program shown below, all of the connections to the servers are using port 443 and https (TLS protocol) -- both the initial connection to login.postini.com and subsequent connections to...
11
2327
by: Michael Foord | last post by:
Has anyone used ClientCookie to store cookies ? I'm going to play around with 'pickling cookies' - but I wondered if anyone had any experience of this. (For session persistence in approx - my...
0
1769
by: Richie Hindle | last post by:
Hi, I'm trying to write a test script to hammer an HTTP server over a persistent HTTP 1.1 connection. The server uses cookies, so I'm using a combination of ClientCookie 0.4.19 and urllib2 with...
9
5738
by: HC | last post by:
Hello, all, I started out thinking my problems were elsewhere but as I have worked through this I have isolated my problem, currently, as a difference between MSDE and SQL Express 2005 (I'll just...
3
3419
by: Steve | last post by:
I am trying to calculate elapsed travel times for flights. My plan is to enter the local departure time, the departure city and the local arrival time and city. These times would be standardised...
0
6912
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...
1
6744
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...
0
6981
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...
0
5348
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,...
0
4488
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...
0
3000
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...
0
1304
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
565
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
188
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.