Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 938509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:39:23+00:00 2026-05-15T21:39:23+00:00

I am using this code: def req(url, postfields): proxy_support = urllib2.ProxyHandler({http : 127.0.0.1:8118}) opener

  • 0

I am using this code:

def req(url, postfields):
    proxy_support = urllib2.ProxyHandler({"http" : "127.0.0.1:8118"})
    opener = urllib2.build_opener(proxy_support) 
    opener.addheaders = [('User-agent', 'Mozilla/5.0')]
    return opener.open(url).read()

To make a simple http get request (using tor as proxy).

Now I would like to know how to make multiple request using the same cookie.

For example:

req('http://loginpage', 'postfields')
source = req('http://pageforloggedinonly', 0)
#do stuff with source
req('http://anotherpageforloggedinonly', 'StuffFromSource')

I know that my function req doesn’t support POST (yet), but I have sent postfields using httplib so I guess I can figure that by myself, but I don’t understand how to use cookies, I saw some examples but they are all one request only, I want to reuse the cookie from the first login request in the succeeding requests, or saving/using the cookie from a file (like curl does), that would make everything easier.

The code I posted I only to illustrate what I am trying to achieve, I think I will use httplib(2) for the final app.

UPDATE:

cookielib.LWPCOokieJar worked fine, here’s a sample I did for testing:

import urllib2, cookielib, os

def request(url, postfields, cookie):
    urlopen = urllib2.urlopen
    cj = cookielib.LWPCookieJar()
    Request = urllib2.Request

    if os.path.isfile(cookie):
        cj.load(cookie)

    opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
    urllib2.install_opener(opener)
    txheaders =  {'User-agent' : 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'}

    req = Request(url, postfields, txheaders)
    handle = urlopen(req)
    cj.save(cookie)
    return handle.read()

print request('http://google.com', None, 'cookie.txt')
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T21:39:23+00:00Added an answer on May 15, 2026 at 9:39 pm

    The cookielib module is what you need to do this. There’s a nice tutorial with some code samples.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 508k
  • Answers 508k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If you take a look at the markup, it is… May 16, 2026 at 4:19 pm
  • Editorial Team
    Editorial Team added an answer It is possible that these students have been taught arrays… May 16, 2026 at 4:19 pm
  • Editorial Team
    Editorial Team added an answer Most likely the message content is encoded using BASE64 or… May 16, 2026 at 4:19 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I am using this code: def startThreads(arrayofkeywords): global i i = 0 while len(arrayofkeywords):
I'm running this scala code on a 32-bit quad-core Core2 system: def job(i:Int,s:Int):Long =
I am using urllib2 to post data to a form. The problem is that
I have the following scala code: package dummy import javax.servlet.http.{HttpServlet, HttpServletRequest => HSReq, HttpServletResponse
Using the tutorial Find Stuff (quick and Dirty) in Advance Rails Recipes, I can
We're using SQLAlchemy declarative base and I have a method that I want isolate
I have a view in my Django application that automatically creates an image using
This feels like a really basic question, but I haven't been able to find
This is my first post, have been a lurker for a long time, so
I am trying to write a function to post form data and save returned

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.