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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:16:44+00:00 2026-05-16T06:16:44+00:00

conn = httplib.HTTPConnection(‘thesite’) conn.request(GET,myurl) conn.putheader(‘Connection’,’Keep-Alive’) #conn.putheader(‘User-Agent’,’Mozilla/5.0(Windows; u; windows NT 6.1;en-US) AppleWebKit/533.4 (KHTML, like Gecko)

  • 0
conn = httplib.HTTPConnection('thesite')
conn.request("GET","myurl")
conn.putheader('Connection','Keep-Alive')
#conn.putheader('User-Agent','Mozilla/5.0(Windows; u; windows NT 6.1;en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome//5.0.375.126 Safari//5.33.4')
#conn.putheader('Accept-Encoding','gzip,deflate,sdch')
#conn.putheader('Accept-Language','en-US,en;q=0.8')
#conn.putheader('Accept-Charset','ISO-8859-1,utf-8;1=0.7,*;q=0.3')
conn.endheaders()
r1= conn.getresponse()

It raises an error:

  conn.putheader('Connection','Keep-Alive')
  File "D:\Program Files\python\lib\httplib.py", line 891, in putheader
    raise CannotSendHeader()

If I comment out putheader and endheaders, it runs fine. But I need it to be keep alive.

Does anyone know what I did wrong?

  • 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-16T06:16:45+00:00Added an answer on May 16, 2026 at 6:16 am

    Use putrequest instead of request. Since request also can send headers, it will send a blank line to the server to indicate end of headers, so sending headers afterward will create an error.

    Alternatively, you could do as is done here:

    import httplib, urllib
    params = urllib.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0})
    headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}
    conn = httplib.HTTPConnection("musi-cal.mojam.com:80")
    conn.request("POST", "/cgi-bin/query", params, headers)
    response = conn.getresponse()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

import httplib conn = httplib.HTTPConnection(head) conn.request(HEAD,tail) res = conn.getresponse() I can get the res.status
if data.find('!search') != -1: nick = data.split('!')[ 0 ].replace(':','') conn = httplib.HTTPConnection(www.md5.rednoize.com) conn.request(GET, ?q=
import httplib conn = httplib.HTTPConnection(head) conn.request(HEAD,tail) res = conn.getresponse() print res.status I am currently
>>> import httplib >>> conn = httplib.HTTPConnection(www.google.com) >>> conn.request(HEAD, /index.html) >>> res = conn.getresponse()
I can pull a any page from wikipedia with import httplib conn = httplib.HTTPConnection(en.wikipedia.org)
I open a connection like this: Using conn as New OdbcConnection(connectionString) conn.Open() //do stuff
I'm trying conn = MySQLdb.connect (host = localhost, user = username, passwd = password,
include(conn.php); $result = mysql_query(SELECT * FROM sggame); while($row = mysql_fetch_assoc($result)); { $id = $row['id'];
Assume the following code: using (SqlConnection conn = new SqlConnection(connectionString)) { ... using (SqlCommand
import httplib def httpCode(theurl): if theurl.startswith(http://): theurl = theurl[7:] head = theurl[:theurl.find('/')] tail =

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.