S
S
s4q2021-07-03 22:46:50
Python
s4q, 2021-07-03 22:46:50

Error unpacking Brotli?

There is such a code

import requests
import gzip
import brotli
import json

def getFlightDetails(query):
  encodings = {
    "": lambda x: x,
    "br": brotli.decompress,
    "gzip": gzip.decompress
  }

  headers = {
    "accept-encoding": "gzip, br",
    "accept-language": "pt-BR,pt;q=0.9,en-US;q=0.8,en;q=0.7",
    "cache-control": "max-age=0",
    "origin": "https://www.flightradar24.com",
    "referer": "https://www.flightradar24.com/",
    "sec-fetch-dest": "empty",
    "sec-fetch-mode": "cors",
    "sec-fetch-site": "same-site",
    "user-agent": "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36"
  }

  url = f'https://data-live.flightradar24.com/clickhandler/?flight={query}'
  request = requests.get(url, headers = headers)

  contentEnc = request.headers.get("Content-Encoding", "")
  content = request.content
  contentType = request.headers.get["Content-Type"]

  content = encodings[contentEnc](content)

  return json.loads(content)

print(getFlightDetails('U6263'))

However, it gives an error
brotli.error: BrotliDecompress failed
What is the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Bl4ckm45k, 2021-07-03
@s4q

brotli.error: BrotliDecompress
failed urlib3 used in requests does what you need with Brotli if it is installed

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question