import requests
URL_AUTH = 'https://developers.lingvolive.com/api/v1/authenticate'
URL_TRANSLATE = 'https://developers.lingvolive.com/api/v1/Minicard'
KEY = 'MY API KEY'
headers_auth = {'Authorization': 'Basic ' + KEY}
auth = requests.post(URL_AUTH, headers=headers_auth)
print(auth.text)
language_1 = 'English'
language_2 = 'russian'
if auth.status_code == 200:
token = auth.text
print(token)
word = input('enter {0}'.format(language_1))
while True:
if word:
headers_translate = {
'Authorization': 'Bearer ' + token
}
params = {
'text': word,
'srcLang': 1033,
'dstLang': 1049
}
r = requests.get(URL_TRANSLATE, headers=headers_translate, params=params)
res = r.json()
try:
print(res['Translation']['Translation'])
except:
print('Не удалось найти слово для перевода')
else:
print('error')
Проверял через postman: все проходит. print(r.status_code)
выдает 401, но нигде не могу найти ошибку, токен тоже находит без проблем.
Traceback (most recent call last):
File "C:/Users/User/Desktop/Django/mysite/art/dcfvedv.py", line 28, in <module>
res = r.json()
File "C:\Users\User\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\models.py", line 900, in json
return complexjson.loads(self.text, **kwargs)
File "C:\Users\User\AppData\Local\Programs\Python\Python38-32\lib\json\__init__.py", line 357, in loads
return _default_decoder.decode(s)
File "C:\Users\User\AppData\Local\Programs\Python\Python38-32\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Users\User\AppData\Local\Programs\Python\Python38-32\lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)