Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Open unuploaded file
#1
I'm using Flask and requests module. And I'm trying to use post request:

file = request.files['file']
files = {'file': open(file.filename)}
r = requests.post(SERVER, files=files)
And in the server:
file = request.files['file']
print(file)
I get the following error:
Error:
files = {'file': open(file.filename)}\nFileNotFoundError: [Errno 2] No such file or directory: 'run.gif'
I think what I'm doing here is open(file.filename) is not reading the uploading file. Because, it doesn't read full path.

So, how can I read temp file?


Or, I'm doing something wrong? Should I send stream data to the server? If so, how should I do that? Please help me understanding to send file to the server.
Reply
#2
Can you open the file with a script which does only that?

I feel like I need more context on this question. You should provide full, runnable code that reproduces your problem, with the minimum reasonable code necessary to reproduce it. I would estimate 10-20 lines, but if you're posting >50 it's definitely too much.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Open and read a tab delimited file from html using python cgi luffy 2 2,633 Aug-24-2020, 06:25 AM
Last Post: luffy
  Open Sqlite database file directly in django sourabhjaiswal92 0 2,922 May-22-2018, 05:55 AM
Last Post: sourabhjaiswal92
  Cannot open file [ERNO 22] INVALID ARGUMENT JoshuaKim02 20 12,676 Jan-04-2018, 07:05 PM
Last Post: JoshuaKim02

Forum Jump:

User Panel Messages

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