473,385 Members | 1,907 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

API requests help

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:

Expand|Select|Wrap|Line Numbers
  1. {"url":"http://s338.turbobit.net/uploadfile","params":{"apptype":"fd1","upload_info":"emwlnJG14T2nXMulBIquHSvz/3zDY2hQPoVMcgl+ZtKTUrBCW1VsclufS71w8q90XRTr0pNTtLRtsbA0dmZ5zuJqfreq++B/Q1S7y5XmjQVvZ+GnRZv/SKLojehhkMo="},"result":true}
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
Expand|Select|Wrap|Line Numbers
  1. import requests
  2.  
  3. url = "https://turbobit.net/v001/upload/http/server"
  4.  
  5. headers = {"X-API-KEY": 'xxxxxxxxxxxxxxxxx'}
  6.  
  7.  
  8. resp = requests.post(url,headers=headers)
  9. print (resp.text)
  10. #prints my response info
  11. response_json = resp.json()
  12. #my file to upload
  13. myfile =(file.zip)
  14.  
  15. #make 2nd post request and including the data.
  16. re = requests.post(resp.json)
  17.  
  18. resp = requests.post(url,headers=headers)
[/code]
i get these errors
Expand|Select|Wrap|Line Numbers
  1.  
  2.  File "C:\Users\pc\Desktop\python\test.py", line 13, in <module>
  3.     myfile =(file.zip)
  4. NameError: name 'file' is not defined. Did you mean: 'filter'?
  5.  
  6.  
and i was getting these errors .

[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
  1.  
  2.  
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.
Feb 23 '22 #1
0 6212

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Ohaya | last post by:
Hi, I'm trying to understand a situation where ASP seems to be "blocking" of "queuing" requests. This is on a Win2K Advanced Server, with IIS5. I've seen some posts (e.g.,...
1
by: slugger | last post by:
Hope this is not OT: I am running into some strange things whenever my ASP pages send out simultaneous requests to another ASP page which in turn gains access to a MySQL database using a DSNless...
2
by: Alex | last post by:
Hello, All. I encouraged some strange behaviour of either IIS, ASP.NET, IE or donn't know what... I have a simple wait.aspx page private void Page_Load(object sender, System.EventArgs e) {...
3
by: sandy | last post by:
I am a student who is losing his mind. The code below is a header file which has the line: void ClearList(ListType *list); which generates the following compile time errors: variable or...
5
by: linda.chen | last post by:
Hi all, We have a webservice (service1), which calls another webservice(service2) from another orginization. Our end users make requests throught service1. When service2 receives a quest, it...
1
by: vikjohn | last post by:
I have a new perl script sent to me which is a revision of the one I am currently running. The permissions are the same on each, the paths are correct but I am getting the infamous : The specified...
2
by: violeta123 | last post by:
I am stuck! Please help It might be difficult to explain the problem via email, but I will try. I have a Win 2003 Enterprise server running with the only purpose of a membership web site...
7
by: =?Utf-8?B?Vkg=?= | last post by:
Hi, all. Need help with what seems to be either connection, or threading problem in my ASP.NET 2.0 application. The gist of the problem is this: IHttpHandler in my application serves an HTML...
0
by: atencorps | last post by:
Hello I have the following code but need some help on it. The idea of the code is the main sections ie Service Management are viewable when the page is loaded and by clicking on the main...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.