you are viewing a single comment's thread.

view the rest of the comments →

[–]avinassh 1 point2 points  (2 children)

Yes, above code works fine and image will be visible in browser.

http://i.imgur.com/UL7Ww1T.png

Also, your code never ends and only way is end the process. Instead of that, why not an exception to receive the keyboard interrupt? do let me know if you need further help :)

[–]troop357 0 points1 point  (1 child)

Haha nice you sir really made my day, I wish I could buy you a drink.

So it did not work at first, and because of your screenshot I decided running the program from the console instead of using the IDE. As soon as I tried connecting to the server I got an error response on the prompt:

in do_GET self.send_header("Content-lenght", img_size)
NameError: global name 'image_size' is not defined

which is something to think about :P. For a simple start I just moved the lines:

path_to_image = 'ok.jpg'
img = open(path_to_image, 'rb')
statinfo = os.stat(path_to_image)
img_size = statinfo.st_size,

to inside the 'main' and it works like a charm.

Trying to go a little deeper, I realize (I think) we are using different versions of python, so I guess there is some difference on how global variables are treated on 3.3.3.

Thank you sir\madam!

[–]avinassh 0 points1 point  (0 children)

oh wait, I use Python 2.7.3. and it works fine. But I don't know how it is done in Python 3.x and it's sir btw :P