allegro / allegro-api

Issue tracker and wiki for Allegro REST API
https://developer.allegro.pl/
217 stars 39 forks source link

[406] Not acceptable representation requested. #10246

Open MateuszCz opened 2 weeks ago

MateuszCz commented 2 weeks ago

Cześć, Staram się dostać listę wątków, ale nie daję rady już na start:

HEADERS = {
    'accept': 'application/vnd.allegro.public.v1+json',
    'content-type': 'application/vnd.allegro.public.v1+json'
}
def check_message(token: str):
    url = 'https://api.allegro.pl/messaging/threads'
    HEADERS.update({'Authorization': f'Bearer {token}'})
    pprint(HEADERS)
    raw = requests.get(url, HEADERS)
    pprint(raw.json())
    pprint(raw.headers)

Dostaję taki response:

{'Authorization': 'Bearer '
                  'JWT',
 'accept': 'application/vnd.allegro.public.v1+json',
 'content-type': 'application/vnd.allegro.public.v1+json'}
{'errors': [{'code': 'NotAcceptableException',
             'details': None,
             'message': 'Not acceptable representation requested. Please check '
                        "'Accept' request header",
             'metadata': {},
             'path': None,
             'userMessage': 'Request contains invalid data. Contact the '
                            'application author.'}]}
{'trace-id': '35eb442d0bb91345', 'content-type': 'application/json; charset=utf-8', 'content-length': '256', 'date': 'Thu, 07 Nov 2024 15:19:35 GMT', 'x-frame-options': 'DENY', 'strict-transport-security': 'max-age=15552000', 'x-content-type-options': 'nosniff'}

Gdzie popełniam błąd?

AureliuszBrussy commented 2 weeks ago

Nagłówki wysyłasz jako query parameter, zamiast faktycznie w headers. Zmieniłbym tą linijkę:

raw = requests.get(url, HEADERS)

na

raw = requests.get(url, headers=HEADERS).