Skip to content

Instantly share code, notes, and snippets.

@Vopaaz
Last active November 7, 2023 09:50
Show Gist options
  • Save Vopaaz/c5da9c71b7ac0723860fd48ffb977f27 to your computer and use it in GitHub Desktop.
Save Vopaaz/c5da9c71b7ac0723860fd48ffb977f27 to your computer and use it in GitHub Desktop.
Converting the directly copied header from Chrome to the header dict that can be used in requests package.
def parse_header(raw_header: str):
header = dict()
for line in raw_header.split("\n"):
if line.startswith(":"):
a, b = line[1:].split(":", 1)
a = f":{a}"
else:
a, b = line.split(":",1)
header[a.strip()] = b.strip()
return header
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment