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 631165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:56:07+00:00 2026-05-13T19:56:07+00:00

I am working with urllib2 , and trying to extract the headers in a

  • 0

I am working with urllib2, and trying to extract the headers in a printable form from a Response object.

Presently I am printing str(response.info()), however what is printed, is itself a Python string (at least to my understanding).

(Pdb) p str(response.info())
'Date: Tue, 23 Feb 2010 03:12:26 GMT\r\nServer: Apache\r\nVary: Accept-Encoding,User-Agent\r\nContent-Encoding: gzip\r\nContent-Length: 9045\r\nConnection: close\r\nContent-Type: text/html; charset=ISO-8859-1\r\n'

I need to turn that string into an “actual” string, such as by evaluation or something similar. The best theoretical solution I’ve found is to use:

s = str(response.info())
print s.decode("string_escape")

But this does not work. Further adding to the confusion is how to handle the quotes within the string, calling eval(s) and str(s) do not work either.

Is there some better way to extract the raw headers in the response without quoting, or a method to decode the string s as above?

  • 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-13T19:56:07+00:00Added an answer on May 13, 2026 at 7:56 pm

    str(info()) does give a normal string:

    >>> import urllib2
    >>> f = urllib2.urlopen('http://tejp.de')
    >>> print str(f.info())
    Connection: close
    Vary: Accept-Encoding
    Content-Type: text/html
    Accept-Ranges: bytes
    ETag: "-807357257"
    Last-Modified: Wed, 01 Jul 2009 10:05:34 GMT
    Content-Length: 285
    Date: Tue, 23 Feb 2010 03:24:10 GMT
    Server: lighttpd/1.4.19
    

    It’s only the debugger’s p command which prints the string in escaped form.

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

Sidebar

Related Questions

Working with an Oracle 9i database from an ASP.NET 2.0 (VB) application using OLEDB.
I'm trying to parse an RSS/Podcast feed using Beautifulsoup and everything is working nicely
I am trying to post a multi-part form using httplib, url is hosted on
First time working with the HTMLParser module. Trying to use standard string formatting on
Working on trying out the market licensing service, and I'm running into a few
Working with Excel interop, I'm trying be very careful about not implicitly creating any
I'm working on a library that involves pre-processing of urllib2.Request instances (using the urllib2.BaseHandler.xxx_request
Working with COM interop, I can call a managed function from within unmanaged code.
Working with dates in ruby and rails on windows, I'm having problems with pre-epoch
Working with a SqlCommand in C# I've created a query that contains a IN

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.