Uploading from requests library in python
Posted: Thu Apr 23, 2020 2:57 pm
Code: Select all
url = 'https://api.wigle.net/api/v2/file/upload'
Code: Select all
data = {'file': (outfile, 'multipart/form-data', {'Expires': '0'})}
Code: Select all
response = requests.post(url, files=data, headers={'Authorization': 'Basic blahblahblah'})
Code: Select all
print(" ")
Code: Select all
response = response.text
Code: Select all
print(response)
I'm trying to upload my .csv from python via the requests library rather than using curl however with requests I keep getting {"code":400,"message":"HTTP 400 Bad Request"} so I must be doing something wrong. I can get it to upload via curl using subprocess but catching the output to see if it succeeded in the upload or failed is giving me troubles so I opted for using requests (plus its a little bit nicer)
Anything blatant that I'm doing wrong? I'm not a huge programmer i just make little projects here and there so i'm still learning.