-2

This is my code:

import requests

url = 'https://api'

files=[('file',('image.png',open('/C:/Users/Swarnitha/Downloads/image.png','rb'),'image/png'))]

#files = {"file":open('/C:/Users/Swarnitha/Downloads/image.png','rb')}


response = requests.post(url, files=files)

In windows I am sending the path of the file like this. I am getting error as:

Traceback (most recent call last):
  File "test.py", line 66, in <module>
    ('file',('image.png',open('/C:/Users/Swarnitha/Downloads/image.png','rb'),'image/png'))
FileNotFoundError: [Errno 2] No such file or directory: '/C:/Users/Swarnitha/Downloads/image.png'

Usually I use to run the same code in ubuntu and give file path from ubuntu software,it use to work.

Please give me solution for this

davidism
  • 121,510
  • 29
  • 395
  • 339
Swarnitha
  • 45
  • 7
  • 1
    remove `/` from the start of the string as it signifies the root directory so you really are trying to access `'C:/C:/...'` (if `C:` is the root directory) – Matiiss Nov 15 '21 at 13:26
  • Does this answer your question? [Windows path in Python](https://stackoverflow.com/q/2953834/6045800) – Tomerikoo Nov 15 '21 at 14:47

1 Answers1

0

Have you tried to change the '/' to '\'. Windows dosen't work with regular /

like :

C:\\Users\\Swarnitha\\Downloads\\image.png or C:\Users\Swarnitha\Downloads\image.png

Jacques
  • 164
  • 8