sorry if this question is dumb, I just can't figure it out but I know I'm close. Please dont roast me too hard
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:
Ok thats my response. SO it gives me a new URL and the other params.
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
[/CODE]
i get these errors
and i was getting these errors .
[CODE]
File "C:\Users\pc\De sktop\python\te st.py", line 12, in <module>
re = requests.post(r esp.json)
File "C:\Users\pc\Ap pData\Local\Pro grams\Python\Py thon310\lib\sit e-packages\reques ts\api.py", line 117, in post
return request('post', url, data=data, json=json, **kwargs)
File "C:\Users\pc\Ap pData\Local\Pro grams\Python\Py thon310\lib\sit e-packages\reques ts\api.py", line 61, in request
return session.request (method=method, url=url, **kwargs)
File "C:\Users\pc\Ap pData\Local\Pro grams\Python\Py thon310\lib\sit e-packages\reques ts\sessions.py" , line 515, in request
prep = self.prepare_re quest(req)
File "C:\Users\pc\Ap pData\Local\Pro grams\Python\Py thon310\lib\sit e-packages\reques ts\sessions.py" , line 443, in prepare_request
p.prepare(
File "C:\Users\pc\Ap pData\Local\Pro grams\Python\Py thon310\lib\sit e-packages\reques ts\models.py", line 318, in prepare
self.prepare_ur l(url, params)
Its pretty confusing for me, I'm trying to teach myself. It took me a long while to actaully get python set up and working .
Feel pretty dumb I've worked on it for 2 days and still can't get anywhere. thanks.
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:
Code:
{"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
Code:
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
Code:
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\De sktop\python\te st.py", line 12, in <module>
re = requests.post(r esp.json)
File "C:\Users\pc\Ap pData\Local\Pro grams\Python\Py thon310\lib\sit e-packages\reques ts\api.py", line 117, in post
return request('post', url, data=data, json=json, **kwargs)
File "C:\Users\pc\Ap pData\Local\Pro grams\Python\Py thon310\lib\sit e-packages\reques ts\api.py", line 61, in request
return session.request (method=method, url=url, **kwargs)
File "C:\Users\pc\Ap pData\Local\Pro grams\Python\Py thon310\lib\sit e-packages\reques ts\sessions.py" , line 515, in request
prep = self.prepare_re quest(req)
File "C:\Users\pc\Ap pData\Local\Pro grams\Python\Py thon310\lib\sit e-packages\reques ts\sessions.py" , line 443, in prepare_request
p.prepare(
File "C:\Users\pc\Ap pData\Local\Pro grams\Python\Py thon310\lib\sit e-packages\reques ts\models.py", line 318, in prepare
self.prepare_ur l(url, params)
Code:
Feel pretty dumb I've worked on it for 2 days and still can't get anywhere. thanks.