473,545 Members | 4,241 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

http request with cookie sending

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

C = Cookie.SimpleCo okie()
C["a"] = "b"

cj = cookielib.Cooki eJar()
cj.set_cookie(C )

in the last line I got:
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "C:\Python24\li b\cookielib.py" , line 1593, in set_cookie
if cookie.domain not in c: c[cookie.domain] = {}
AttributeError: 'SimpleCookie' object has no attribute 'domain'

why?
maybe.. there is any code example for sending cookie with some http
request operation?

thanks alot,
Itay.

Apr 18 '06 #1
2 3077
itay_k wrote:
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.


You have to use a cookielib.Cooki e, not Cookie.SimpleCo okie():

import cookielib, urllib2

cj = cookielib.Cooki eJar()
cookie = cookielib.Cooki e(...your cookie data here...)
cj.set_cookie(c ookie)

opener = urllib2.build_o pener(urllib2.H TTPCookieProces sor(cj))
urllib2.install _opener(opener)

data = urllib2.urlopen (...).read()

Kent
Apr 19 '06 #2
Kent Johnson <ke**@kentsjohn son.com> writes:
itay_k wrote:
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.


You have to use a cookielib.Cooki e, not Cookie.SimpleCo okie():


As I mention in the other thread Itay started, he probably doesn't
want to do that either.
John

Apr 20 '06 #3

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

Similar topics

7
9267
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
7
7170
by: What-a-Tool | last post by:
How does the expire date work setting it server side with asp. I know with javascript setting it client side it will be set to the clients local time, and therefore expire when the clients local time reaches the set expire-time. But if it is an expire time set on my server in California, and the cookie is put on a computer that is running...
6
2411
by: Drew | last post by:
I have been trying to figure out why I am getting this message... I have an application that is 20 different ASP pages that works in sequential order (step1, step2, step3...). After each step the app writes the entered text to a cookie. This feature is so that if there is a problem, we can still retrieve the data. This Bad Request error...
4
2070
by: Tim Smith | last post by:
Hi, We have an ASP.NET web application which is suffering performance problems. Since setting up robot scripting interacting with the browser would take a while I hoped I could open a two-way socket with IIS and replicate the HTTP session information e.g. starting out with POST /192.168.1.1/login.aspx HTTP/1.1\r\n Accept-Language:...
1
2256
by: achoo | last post by:
Is it possible to extend a Web service proxy so that it understands an HTTP refresh page? Explanation: * The Web service proxy was autogenerated by Visual Studio .NET 2003 from the Web service's WSDL. It inherits from System.Web.Services.Protocols.SoapHttpClientProtocol. * The Web service is hiding behind a load-balancing content switch
13
13759
by: yawnmoth | last post by:
Say I wrote an ajax script to send out HTTP requests via ajax. Any cookies that I have associated with that site will be sent along with this HTTP request. Is there a way to prevent this from happening? I tried the following to no avail: http.setRequestHeader('Cookie','');
6
2440
by: thomson | last post by:
Hi All, i do hae a solution in which i do have mulitple projects including Web Projects,, Depending on the functionality it gets redirected to different web projects and it is working fine, for eg: http:DomainName/MainProject/index.aspx, If i login, it gets redirectes to a different Web Project inside the solution like...
1
3123
by: Shashank | last post by:
Hi all, I am a new member of this community. I am making a http request to a html file placed on a Apache server. On this page there is an embeded perl statement which requires reading environment variables from the server. When I am typing the url of the html page in my browser, I am able to read the Environment variables from the server...
0
1540
by: darfur | last post by:
I'm writing an application that simplifies the interface to a few websites I use at my job. One of the web servers has a tendency to cause my program to throw a time out exception for a variety of reasons. This is an issue since this web site uses a persistent connection to keep you logged in. So if the request isn't finished and received by my...
0
7396
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
7656
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. ...
0
7805
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
7413
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...
1
5323
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
4943
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...
1
1874
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 we have to send another system
1
1012
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
700
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.