Uploading from requests library in python

Suggestions for WiGLE/JiGLE/DiGLE

3 posts • Page 1 of 1

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)
(sry for bad formatting not sure how to post multi-line code snippets nicely)

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.
Image
You're close! Multipart wants a name.
Try something like:

Code: Select all

data = {'file': ('outfile_name.csv', open('path/to/file/outfile_name.csv', 'rb'), 'multipart/form-data', {'Expires': '0'})}
Oh my goodness! I was close! I got it all working now. I'll have to make a post or something to share the project i'm working on, I think its kinda neat.
Thanks so much Arkasha
Image

3 posts • Page 1 of 1

Return to “WiGLE Project Suggestions”

Who is online

Users browsing this forum: No registered users and 4 guests