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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:07:29+00:00 2026-06-10T23:07:29+00:00

I am trying to use http-parser and write the response to a file following

  • 0

I am trying to use http-parser and write the response to a file following the example here. This is what I am trying to do, I changed the GET request to request an image and then trying to save it to a file:

open('image.jpg', 'wb').write(p.body_file().read())

But the file has zero bytes. What am I missing here?

Complete code:

#!/usr/bin/env python
import socket

from http_parser.http import HttpStream
from http_parser.reader import SocketReader

def main():
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    try:
        s.connect(('www.linux-mag.com', 80))
        s.send("GET http://www.linux-mag.com/s/i/topics/tux.jpg HTTP/1.1\r\nHost: www.linux-mag.com\r\n\r\n")
        r = SocketReader(s)
        p = HttpStream(r)
        print p.body_file()
        open('image.jpg', 'wb').write(p.body_file().read())
    finally:
        s.close()

if __name__ == "__main__":
    main()
  • 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-06-10T23:07:31+00:00Added an answer on June 10, 2026 at 11:07 pm

    It turns out that I needed to sudo the script. I did sudo python <script> it works fine.

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

Sidebar

Related Questions

I'm trying to use this http://www.rcsb.org/pdb/software/rest.do REST services with Qt. I did some get
I am trying to use JavaScript to upload image to imgur by this example
I'm trying to use a SAX parser to parse a HTTP response. Everything seems
I'm trying to use a simple HTTP get to load a string from a
I'm trying to use this font: http://www.fontsquirrel.com/fontfacedemo/eb-garamond So I download the type kit and
for some reason I get this error below when trying to use multiple require()
I am trying to get an HTML page source content from this site: http://207.200.96.231:8008
I am trying to install HTML-Parser-3.64 and I get following report while running make
I am trying to use dis-max query parser ( http://localhost:8983/solr/select/?q=name&qt=defType=dismax ) So can you
I was trying to use http://www.jongsma.org/gc/scripts/ofx-ba.py to grab my bank account information from wachovia.

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.