myfile = open(datafile, 'rb') not working - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: myfile = open(datafile, 'rb') not working (/thread-21696.html) |
myfile = open(datafile, 'rb') not working - mford29_programmer - Oct-10-2019 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 RE: myfile = open(datafile, 'rb') not working - perfringo - Oct-10-2019 It should, if your code contains this row: url = http:\\11.11.11.11 # invalid syntax, must be string RE: myfile = open(datafile, 'rb') not working - mford29_programmer - Oct-10-2019 sorry, my bad, it is a string in the code, I just changed the address and forgot to put "" around it RE: myfile = open(datafile, 'rb') not working - buran - Oct-10-2019 Don't use general except clause that will mask what the error is. Remove the try/except to get exception description RE: myfile = open(datafile, 'rb') not working - mford29_programmer - Oct-10-2019 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 :) |