ok I'm pretty new at python but I've been having this problem
What I'm trying to do is upload a file via api using Requests and pyhon
Actually I have to make 2 post requests. The first one I include my api key and I get this response:
Expand|Select|Wrap|Line Numbers
- {"url":"http://s338.turbobit.net/uploadfile","params":{"apptype":"fd1","upload_info":"emwlnJG14T2nXMulBIquHSvz/3zDY2hQPoVMcgl+ZtKTUrBCW1VsclufS71w8q90XRTr0pNTtLRtsbA0dmZ5zuJqfreq++B/Q1S7y5XmjQVvZ+GnRZv/SKLojehhkMo="},"result":true}
Now my problem is to make another post and include the response data and the file I want to upload.
Here is my code I've tried
Expand|Select|Wrap|Line Numbers
- import requests
- url = "https://turbobit.net/v001/upload/http/server"
- headers = {"X-API-KEY": 'xxxxxxxxxxxxxxxxx'}
- resp = requests.post(url,headers=headers)
- print (resp.text)
- #prints my response info
- response_json = resp.json()
- #my file to upload
- myfile =(file.zip)
- #make 2nd post request and including the data.
- re = requests.post(resp.json)
- resp = requests.post(url,headers=headers)
i get these errors
Expand|Select|Wrap|Line Numbers
- File "C:\Users\pc\Desktop\python\test.py", line 13, in <module>
- myfile =(file.zip)
- NameError: name 'file' is not defined. Did you mean: 'filter'?
[code]
File "C:\Users\pc\Desktop\python\test.py", line 12, in <module>
re = requests.post(resp.json)
File "C:\Users\pc\AppData\Local\Programs\Python\Python3 10\lib\site-packages\requests\api.py", line 117, in post
return request('post', url, data=data, json=json, **kwargs)
File "C:\Users\pc\AppData\Local\Programs\Python\Python3 10\lib\site-packages\requests\api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Users\pc\AppData\Local\Programs\Python\Python3 10\lib\site-packages\requests\sessions.py", line 515, in request
prep = self.prepare_request(req)
File "C:\Users\pc\AppData\Local\Programs\Python\Python3 10\lib\site-packages\requests\sessions.py", line 443, in prepare_request
p.prepare(
File "C:\Users\pc\AppData\Local\Programs\Python\Python3 10\lib\site-packages\requests\models.py", line 318, in prepare
self.prepare_url(url, params)
Expand|Select|Wrap|Line Numbers
Feel pretty dumb I've worked on it for 2 days and still can't get anywhere. thanks.