Answer the question
In order to leave comments, you need to log in
Why do requests to "Balabob" return 403? And how to do it right?
I am writing a script for working with the "Balabob" neuron in Python 3.8.5. According to site requests, you can understand that the api is extremely simple there, however, it is not clear why, when requesting a page, the site decides to return 403 to me with a page like this:
I tried to throw a request from both the home and the server - everything is the same.
The query I'm sending is extremely simple:
import requests
result = requests.post('https://zeapi.yandex.net/lab/api/yalm/text3', json={
'filter': 1,
'intro': 0,
'query': "Пошёл я как-то гулять"
}, headers={
"Content-Type": "application/json"
})
print(result.text)
Answer the question
In order to leave comments, you need to log in
Throw it out requests
and use the urllib.request
working version, python 3.8-3.9:
import json
import urllib.request
headers = {
'Content-Type': 'application/json',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 11_4) AppleWebKit/605.1.15 '
'(KHTML, like Gecko) Version/14.1.1 Safari/605.1.15',
'Origin': 'https://yandex.ru',
'Referer': 'https://yandex.ru/',
}
API_URL = 'https://zeapi.yandex.net/lab/api/yalm/text3'
payload = {"query": "Ура Хабр", "intro": 0, "filter": 1}
params = json.dumps(payload).encode('utf8')
req = urllib.request.Request(API_URL, data=params, headers=headers)
response = urllib.request.urlopen(req)
print(response.read().decode('utf8'))
import requests
import json
url = "https://zeapi.yandex.net/lab/api/yalm/text3"
payload = json.dumps({
"filter": 1,
"into": 0,
"query": "Тест был"
})
headers = {
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question