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

  • SEARCH
  • Home
  • 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 6788567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:30:04+00:00 2026-05-26T17:30:04+00:00

I am using Python 2.6.5 and I am trying to capture the raw http

  • 0

I am using Python 2.6.5 and I am trying to capture the raw http request sent via HTTP, this works fine except when I add a proxy handler into the mix so the situation is as follows:

  • HTTP and HTTPS requests work fine without the proxy handler: raw HTTP request captured
  • HTTP requests work fine with proxy handler: proxy ok, raw HTTP request captured
  • HTTPS requests fail with proxy handler: proxy ok but the raw HTTP request is not captured!

The following questions are close but do not solve my problem:

  • How do you get default headers in a urllib2 Request? <- My solution is heavily based on this
  • Python urllib2 > HTTP Proxy > HTTPS request
  • This sets the proxy for each request <- Did not work and doing it once at the start via an opener is more elegant and efficient (instead of setting the proxy for each request)

This is what I am doing:

class MyHTTPConnection(httplib.HTTPConnection):
    def send(self, s):
            global RawRequest
            RawRequest = s  # Saving to global variable for Requester class to see
            httplib.HTTPConnection.send(self, s)

class MyHTTPHandler(urllib2.HTTPHandler):
    def http_open(self, req):
            return self.do_open(MyHTTPConnection, req)

class MyHTTPSConnection(httplib.HTTPSConnection):
    def send(self, s):
            global RawRequest
            RawRequest = s  # Saving to global variable for Requester class to see
            httplib.HTTPSConnection.send(self, s)

class MyHTTPSHandler(urllib2.HTTPSHandler):
    def https_open(self, req):
            return self.do_open(MyHTTPSConnection, req)

Requester class:

global RawRequest
ProxyConf = { 'http':'http://127.0.0.1:8080', 'https':'http://127.0.0.1:8080' }
# If ProxyConf = { 'http':'http://127.0.0.1:8080' }, then Raw HTTPS request captured BUT the proxy does not see the HTTPS request!
# Also tried with similar results:     ProxyConf = { 'http':'http://127.0.0.1:8080', 'https':'https://127.0.0.1:8080' }
ProxyHandler = urllib2.ProxyHandler(ProxyConf)
urllib2.install_opener(urllib2.build_opener(ProxyHandler, MyHTTPHandler, MyHTTPSHandler))
urllib2.Request('http://www.google.com', None) # global RawRequest updated
# This is the problem: global RawRequest NOT updated!?
urllib2.Request('https://accounts.google.com', None) 

BUT, if I remove the ProxyHandler it works!:

global RawRequest
urllib2.install_opener(urllib2.build_opener(MyHTTPHandler, MyHTTPSHandler))
urllib2.Request('http://www.google.com', None) # global RawRequest updated
urllib2.Request('https://accounts.google.com', None) # global RawRequest updated

How can I add the ProxyHandler into the mix while keeping access to the RawRequest?

Thank you in advance.

  • 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-26T17:30:04+00:00Added an answer on May 26, 2026 at 5:30 pm

    Answering my own question: It seems a bug in the underlying libraries, making RawRequest a list solves the problem: The HTTP Raw request is the first item. The custom HTTPS class is called several times, the last of which is blank. The fact that the custom HTTP class is only called once suggests this is a bug in python but the list solution gets around it

    RawRequest = s
    

    just needs to be changed to:

    RawRequest.append(s)
    

    with a previous initialisation of RawRequest = [] and retrieval of raw request via RawRequest[0] (first element of the list)

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

Sidebar

Related Questions

I'm using Python 2.5. I'm trying to use this 'with' statement. from __future__ import
I'm trying to create an xml entry that looks like this using python and
I am trying to send Binary data using python raw socket. For that i
I'm trying to ping Pingomatic using python. I've written this: import xmlrpclib print START
Using Python, I'm trying to parse a string like this: hello I am an
I'm trying to capture the output of a windows program using Qt and Python.
I am using Python 2.6 and am trying to run a simple random number
I am trying to talk to a device using python. I have been handed
i m trying to design a mmo game using python... I have evaluated stackless
I'm trying to calculate the sunset / rise times using python based on the

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.