Python Forum
myfile = open(datafile, 'rb') not working
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
myfile = open(datafile, 'rb') not working
#1
Morning All,
i'm trying to write code to use requests.post() but it keeps skipping the try and printing 'Error' with one particular line.

try:
    url = http:\\11.11.11.11    # url changed for security
    print(url)
    myFile = open(<datafile>, 'rb')    # This is the line i'm having issues with
    files = {'file': myFile}
    #print(files)
    r = requests.post(url, file=files)
except:
    print('Error')
any help would be greatly appreciated
Many Thanks
Reply
#2
It should, if your code contains this row:

url = http:\\11.11.11.11     # invalid syntax, must be string
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#3
sorry, my bad, it is a string in the code, I just changed the address and forgot to put "" around it
Reply
#4
Don't use general except clause that will mask what the error is. Remove the try/except to get exception description
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
After taking away the try/except I found out why it wasn't liking it. The path was not recognized.
I retyped the path and it worked, only problem is that after double checking the previous path was actually correct with no errors but for some reason retyping it worked.
Confused yes, but it's working :)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Use of IdnexData on datafile Led_Zeppelin 0 762 Aug-14-2022, 05:44 PM
Last Post: Led_Zeppelin
  Stock Rate of Change (based on open and current price) Not Working firebird 1 2,335 Jul-29-2019, 07:10 AM
Last Post: perfringo
  Last Line of datafile not loading salehin 1 2,726 Aug-21-2017, 06:05 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020