473,396 Members | 1,775 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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_username=psyca&j_password=******',{
'Cookie':'sab=contextUrl+https%3A%2F%2Fwwws.vexbr. com.br%2Fcafedev%2F%7CnasIp+10.50.0.3%7CneedCheckC ode+false%7ClocationId+85%7CautoLogout+false%7Cser viceProviderId+1%7CorigUrl+%2Findex.html%7CwebCont ext+cafedev%7CclientIp+192.168.1.107%7CnasId+vex_c afedev%7CloginType+0%7Cclass+class+com.wificom.sab .aaa.dto.SessionDTO%7CloginResumed+false%7CloggedI n+false%7Clanguage+en%7CpricingPlanId+0%7CsslPort+ 443%7CroamingPriceId+0%7CclientMac+00%3A07%3A95%3A D3%3A0C%3A7C%7CserverUrl+https%3A%2F%2Fwwws.vexbr. com.br%2F',
'Cookie':'JSESSIONID=DFA58D39389BA5E3CEB5C92F93087 92C',
'Content-type':'application/x-www-form-urlencoded',
'Content-length':str(len('j_username=psyca&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=DFA58D39389BA5E3CEB5C92F9308792C
Content-length: 34
Content-type: application/x-www-form-urlencoded

j_username=psyca&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 2327
"Rafael T. Ugolini" <ra****@vexbr.com.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_username=psyca&j_password=******',{
'Cookie':'sab=contextUrl+https%3A%2F%2Fwwws.vexbr. com.br%2Fcafedev%2F%7CnasIp+10.50.0.3%7CneedCheckC ode+false%7ClocationId+85%7CautoLogout+false%7Cser viceProviderId+1%7CorigUrl+%2Findex.html%7CwebCont ext+cafedev%7CclientIp+192.168.1.107%7CnasId+vex_c afedev%7CloginType+0%7Cclass+class+com.wificom.sab .aaa.dto.SessionDTO%7CloginResumed+false%7CloggedI n+false%7Clanguage+en%7CpricingPlanId+0%7CsslPort+ 443%7CroamingPriceId+0%7CclientMac+00%3A07%3A95%3A D3%3A0C%3A7C%7CserverUrl+https%3A%2F%2Fwwws.vexbr. com.br%2F',
'Cookie':'JSESSIONID=DFA58D39389BA5E3CEB5C92F93087 92C',
'Content-type':'application/x-www-form-urlencoded',
'Content-length':str(len('j_username=psyca&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.urlopen(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.urlopen(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
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,...
5
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",...
2
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...
2
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
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
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...
6
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 =...
0
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...
1
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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...
0
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,...
0
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
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,...

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.