Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

Urllib2 to save a image

I'm having some issues with my Twitter Bot. The bot works perfectly but I'm having the issues with the image part. It currently posts the same image every time the tweet is sent when it should be posting the new one that urllib2 got and saved into the image. I don't get any errors but I believe its because I didn't add image.close(). I tried adding image.close() but I keep getting "ValueError: I/O operation on closed file" where ever I put it in the code. I tried attaching the code on in the thread but Hack Forums firewall blocked it. Instead, I have attached Leet Files and Paste Bin links. Thanks ahead of time.

Paste Bin: here
Leet Files: here


Why not just paste it here?
(Dec 24, 2017 07:06 PM)Not Your Average Orange Wrote:  Why not just paste it here?

Sorry I was in a hurry and didn't have time to copy and paste. I attached the code now.



I’m still having this issue and it would be great to receive help. Thanks!


(Dec 27, 2017 11:11 AM)CleverUSB Wrote:  I’m still having this issue and it would be great to receive help. Thanks!

So, as I understand it, you are using the image variable as a writable bytes object to "print" your image to. That's perfectly okay as it is, just make sure you close it out at the end of the program before exiting. I think your problem lies with updating the snapshot. Notice that your loop never updates the image variable with the new one grabbed, so essentially it is repeatedly writing the same currentPrintImage variable into the image variable. I would do it differently like so...

https://pastebin.com/THqrRt1T

If I am understanding your logic correctly, if you move your currentPrintImage inside of your while loop and re-assign it by calling the urllib.urlopen("http://blah.blah") BEFORE it is read() into the image file object you created, then this should update the image with a fresh snapshot each time. 🤝
Malware Dev & Grey Hat available for contract work. DM if you need me.

OSCP, OSCE, OSEE, OSWE, OSWP, CEH, CISSP

Yeah, I've been around a while
(Dec 28, 2017 09:43 AM)Nomad.Null Wrote:  So, as I understand it, you are using the image variable as a writable bytes object to "print" your image to. That's perfectly okay as it is, just make sure you close it out at the end of the program before exiting. I think your problem lies with updating the snapshot. Notice that your loop never updates the image variable with the new one grabbed, so essentially it is repeatedly writing the same currentPrintImage variable into the image variable. I would do it differently like so...

https://pastebin.com/THqrRt1T

If I am understanding your logic correctly, if you move your currentPrintImage inside of your while loop and re-assign it by calling the urllib.urlopen("http://blah.blah") BEFORE it is read() into the image file object you created, then this should update the image with a fresh snapshot each time. 🤝

Thanks for reviewing my code. It helped alot.




Possibly Related Threads...
Thread / Author Replies Views Last Post
[C#] by C++Dec 29, 2019 06:16 PM 16 831 Dec 29, 2019 06:16 PM
Last Post: DNA
[Python] by OracleJul 6, 2019 01:26 AM 2 144 Jul 6, 2019 01:26 AM
Last Post: Oracle
[Python] by DistrictApr 7, 2019 03:14 AM 4 230 Apr 7, 2019 03:14 AM
Last Post: lockhead