Super Simple Python to Get Response from Streaming Site API

momowriter

Regular Member
Joined
Nov 22, 2018
Messages
286
Reaction score
106
hi guys, I'm super new to Python,

I have a list of streaming site codes, and I just want to check if it's dead or inactive or working,
I went online and they say using python would be the best solution, i'm using streamtape API btw,

I copied a simple code as below and tried to get it to work on python but I keep getting 403 error,

import requests

login = 'myloginfjkfdlsjlk'
key = 'mykeyblahblahblah'
file = 'XorQOyJrdDhzpB'
response = requests.get('https://api.streamtape.com/file/info?file={file}&login={login}&key={key}')
print(response.json())

I think I'm missing something here,
please help a simple fix is all I need. at least to get a 200 response would do wonders in pushing me ahead!

Thanks
 
Try sending User Agent in request, like so:
Code:
import requests

login = 'myloginfjkfdlsjlk'
key = 'mykeyblahblahblah'
file = 'XorQOyJrdDhzpB'
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'}

response = requests.get('https://api.streamtape.com/file/info?file={file}&login={login}&key={key}', headers=headers)
print(response.json())
 
I think you just forgot to add the "f", try this:
Code:
response = requests.get(f'https://api.streamtape.com/file/info?file={file}&login={login}&key={key}')
 
I think you just forgot to add the "f", try this:
Code:
response = requests.get(f'https://api.streamtape.com/file/info?file={file}&login={login}&key={key}')
The 'f' coming from where? The syntax looks good, he gets 403 Forbidden, it may be because the URL is malformed, I would get rid of curly braces there
 
hi guys,

solved it mate,
appending .format( file=file, login=login, key=key) to the end of that line solved it~

Thanks for the replies
 
The 'f' coming from where? The syntax looks good, he gets 403 Forbidden, it may be because the URL is malformed, I would get rid of curly braces there
The 'f' is to format the string. The {} ones are the variable names but he never uses the formatting stuff so the string is taken literally.
Try to print the url without the f in front of the string and with the f in front and you'll see the difference.

fstrings, you need to install the pip. its really useful one

It's by default starting from Python 3.6 or 3.7.
 
Back
Top