473,549 Members | 2,733 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

More than one cookie with urllib2

Im trying to add more than one cookie with urllib2 but im not getting
much sucess.
An example...

req = urllib2.Request ('http://localhost','j_u sername=psyca&j _password=***** *',{
'Cookie':'sab=c ontextUrl+https %3A%2F%2Fwwws.v exbr.com.br%2Fc afedev%2F%7Cnas Ip+10.50.0.3%7C needCheckCode+f alse%7Clocation Id+85%7CautoLog out+false%7Cser viceProviderId+ 1%7CorigUrl+%2F index.html%7Cwe bContext+cafede v%7CclientIp+19 2.168.1.107%7Cn asId+vex_cafede v%7CloginType+0 %7Cclass+class+ com.wificom.sab .aaa.dto.Sessio nDTO%7CloginRes umed+false%7Clo ggedIn+false%7C language+en%7Cp ricingPlanId+0% 7CsslPort+443%7 CroamingPriceId +0%7CclientMac+ 00%3A07%3A95%3A D3%3A0C%3A7C%7C serverUrl+https %3A%2F%2Fwwws.v exbr.com.br%2F' ,
'Cookie':'JSESS IONID=DFA58D393 89BA5E3CEB5C92F 9308792C',
'Content-type':'applicat ion/x-www-form-urlencoded',
'Content-length':str(len ('j_username=ps yca&j_password= ******'))}) urllib2.urlopen (req)


nebula:/home/nebuloso# nc -l -p 80
POST / HTTP/1.0
Host: localhost
User-agent: Python-urllib/2.1
Cookie: JSESSIONID=DFA5 8D39389BA5E3CEB 5C92F9308792C
Content-length: 34
Content-type: application/x-www-form-urlencoded

j_username=psyc a&j_password=** ****

---
and another thing , headers is a dic , you cant add 2 equal keys...
dunno how to do it.

Thanks.
Jul 18 '05 #1
5 2338
"Rafael T. Ugolini" <ra****@vexbr.c om.br> writes:
Im trying to add more than one cookie with urllib2 but im not getting
much sucess.
An example...

req = urllib2.Request ('http://localhost','j_u sername=psyca&j _password=***** *',{
'Cookie':'sab=c ontextUrl+https %3A%2F%2Fwwws.v exbr.com.br%2Fc afedev%2F%7Cnas Ip+10.50.0.3%7C needCheckCode+f alse%7Clocation Id+85%7CautoLog out+false%7Cser viceProviderId+ 1%7CorigUrl+%2F index.html%7Cwe bContext+cafede v%7CclientIp+19 2.168.1.107%7Cn asId+vex_cafede v%7CloginType+0 %7Cclass+class+ com.wificom.sab .aaa.dto.Sessio nDTO%7CloginRes umed+false%7Clo ggedIn+false%7C language+en%7Cp ricingPlanId+0% 7CsslPort+443%7 CroamingPriceId +0%7CclientMac+ 00%3A07%3A95%3A D3%3A0C%3A7C%7C serverUrl+https %3A%2F%2Fwwws.v exbr.com.br%2F' ,
'Cookie':'JSESS IONID=DFA58D393 89BA5E3CEB5C92F 9308792C',
'Content-type':'applicat ion/x-www-form-urlencoded',
'Content-length':str(len ('j_username=ps yca&j_password= ******'))}) urllib2.urlopen (req)
[...]

Blech.

and another thing , headers is a dic , you cant add 2 equal keys...
dunno how to do it.

[...]

If you want to stay sane, use this:

http://wwwsearch.sourceforge.net/ClientCookie

just say:

ClientCookie.ur lopen(req)
and forget about cookies. If you insist on doing it by hand, though:
you need to join your key=value pairs with semicolons:

Cookie: foo=bar; spam=eggs
John
Jul 18 '05 #2
"John J. Lee" wrote:

If you want to stay sane, use this:

http://wwwsearch.sourceforge.net/ClientCookie

just say:

ClientCookie.ur lopen(req)

and forget about cookies.


As the author, John might seem biased, but I'll weigh in with my own
praise for the product. His comment "if you want to stay sane" is
really on-the-mark here... Cookies _are_ insane, but ClientCookie at
least provides them a nice padded room in which to reside...

Thanks, John! :-)

-Peter
Jul 18 '05 #3
Peter Hansen <pe***@engcorp. com> writes:
As the author, John might seem biased, but I'll weigh in with my own
praise for the product. His comment "if you want to stay sane" is
really on-the-mark here... Cookies _are_ insane, but ClientCookie at
least provides them a nice padded room in which to reside...


Cookies aren't insane in concept, but their implementation leaves some
things to be desired.
Jul 18 '05 #4
Paul Rubin wrote:

Peter Hansen <pe***@engcorp. com> writes:
As the author, John might seem biased, but I'll weigh in with my own
praise for the product. His comment "if you want to stay sane" is
really on-the-mark here... Cookies _are_ insane, but ClientCookie at
least provides them a nice padded room in which to reside...


Cookies aren't insane in concept, but their implementation leaves some
things to be desired.


Agreed... especially with IE6.1, where I still have an incredibly annoying
problem with a Zope-based Intranet where my cookies are being forgotten
periodically, which among other things has led to repeated data loss
(when combined with anothe IE peculiarity which loses the data in the input
fields of a form if the form submission fails... when you hit "back" you
no longer have your data to resubmit).

Oh, but I'm describing a problem with a _Microsoft_ product, so the whole
comment was redundant. Sorry.

-Peter
Jul 18 '05 #5
Peter Hansen <pe***@engcorp. com> writes:
[...]
Cookies aren't insane in concept, but their implementation leaves some
things to be desired.


Agreed... especially with IE6.1, where I still have an incredibly annoying
problem with a Zope-based Intranet where my cookies are being forgotten
periodically, which among other things has led to repeated data loss

[...]

Do you know why / when / which? Are these cookies in your browser or
your users' browsers? Third party? Session or persistent?

I ask because browser behaviour is the only standard in use, really.
Guess which browser?

Of course, cookies are "allowed" to vanish at random times. I
remember reading something about servers telling browsers which
cookies are important to users and shouldn't be thrown away, but I've
completely forgotten where that was...
John
Jul 18 '05 #6

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

Similar topics

7
4313
by: N.K | last post by:
Hi , Python's existing cookie module doesnt supports new cookie headers SetCookie2 , How to submit a patch for that ? I tried emailing person who owns that module.But no response. Thanks, Nirmal
5
5173
by: Alex Hunsley | last post by:
I'm using urllib to post data to a web form by issuing a command similar to this: filename, headers = urllib.urlretrieve("http://www.thewebsitenamehere.com/servlet/com.blah.bloo.XmlFeed", "content.txt", None, urllib.urlencode({"aParameter": "theValue"})) Now, the problem is that the above fails, since I am not sending a session cookie....
2
6272
by: Eino Mäkitalo | last post by:
It seems that urrlib2 default redirection does not allow me to handle Cookies. Service I'm trying seems to use IP switcher and session id's with cookies. After successful login it changes session id (PD-H_SESSION-ID) in 302 Moved temporarily. Urllib2 is so clever that it handles redirection but with wrong cookies. Some hookings? Just own...
2
3079
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
7
19065
by: itay_k | last post by:
Hi, I dont understand why this is so complicated, just to add one line of cookie header on the GET request. This is my unworking code: import time import Cookie import cookielib, urllib2
1
1851
by: BJörn Lindqvist | last post by:
Hello, I have some very serious trouble getting cookes to work. After a lot of work (urllib2 is severly underdocumented, arcane and overengineerd btw) I'm finally able to accept cookes from a server. But I'm still unable to return them to a server. Specifically the script im trying to do logs on to a server, get a session cookie and then...
6
5291
by: Alessandro Fachin | last post by:
Hi, i am trying to forge a new cookie by own with cookielib. But i don't still have success. This a simply code: import cookielib, urllib, urllib2 login = 'Ia am a cookie!' cookiejar = cookielib.CookieJar() urlOpener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar)) values = {'user':login} data = urllib.urlencode(values)...
0
3693
by: johnpollard | last post by:
For some reason this script isn't working and I dont know what it is. I believe the problem lies in the following lines of code since the script works with a different website and username/password combination: resp = opener.open('http://www.amm.com/login.asp') theurl = 'http://www.amm.com/login.asp'...
1
5501
by: Gilles Ganault | last post by:
Hello I need a library that supports both going out through a proxy, and handling cookies automagically (the server uses a sessionID to keep track of the user). UrlLib2 supports the proxy part, httplib2 supports the cookie part but... Google didn't return code that shows both uses in the same library. Does someone know if either of...
0
7524
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7451
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...
0
7960
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7475
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...
0
6048
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...
1
5372
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...
0
5089
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...
0
3483
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1061
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.