Skip to main content

Fake Http Header

fake-http-header is a python package that you can use to generate random request fields for a http header. The generated header fields look like they might come from a real internet browser. It is accomplished by mapping browsers to default values and emulating real user behaviour. You can utilize this package, for instance, to write crawlers or testing web applications.

Installation

The easiest way to install this package is using pip. In case you have pip on your system, just type the following command into your terminal prompt:

pip install fake-http-header

Quick Start

Generating a random http header is quite straight forward. Just import the package and call the construcor method for the FakeHttpHeader class without any parameters.

Example:

from fake_http_header import FakeHttpHeader

fake_header = FakeHttpHeader()
print(fake_header)

Output:

FakeHttpHeader(user_agent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.55 Safari/537.36 Edg/96.0.1054.43', accept_language='en-GB',  accept_encoding='identit,b',  accept='text/html, application/xhtml+xml, image/jxr, */*', referer='http://www.intute.ac.uk')

As you can see, the generated header contains an Accept-Language field, which states that the client prefers british english (accept_language='en-GB'). To make this header look more plausible, the referrer site is thereby generated from a pool of .uk domains.

It is also possible to specify of which top level domain the referer site should be. In that case, a fitting Accept-Language field will be generated.

Example:

fake_header = FakeHttpHeader(domain_code = 'de')
print(fake_header)

Output:

FakeHttpHeader(user_agent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36', accept_language='de', accept_encoding='deflat,b,compres', accept='text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8', referer='http://www.netluchs.de')

When working with other python libraries like requests, it is necessary to transform our fake_header object into a dictionary representation that is compatible with the request library. For this purpose, the FakeHttpHeader class provides the as_header_dict method.

import requests

my_url = https://github.com/
fake_header_dict = fake_header.as_header_dict()

r = requests.get(my_url, headers=fake_header_dict)

Future ideas

  • Add weights to certain header fields (e.g. Accept: text/html, application/xhtml+xml, application/xml;q=0.9)

Contributing

Feel free to create pull requests and discuss some new to ideas to make the package more powerful.

Some nice stats about the project

Downloads Downloads

Release files for fake-http-header 0.3.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for fake-http-header 0.3.5
File Interpreter ABI Platform
fake_http_header-0.3.5-py3-none-any.whl Python 3 none any Details

Release files / fake_http_header-0.3.5-py3-none-any.whl

Download URL fake_http_header-0.3.5-py3-none-any.whl
Size 14.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cd05f4bebf1b7e38b5f5c03d7fb820c0c17e87d9614fbee0afa39c32c7a2ad3c
BLAKE2b-256 checksum
How to use checksums
e30b2849c87d9f13766e29c0a2f4d31681aa72e035016b251ab19d99bde7b592
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.3

Release history Release notifications | RSS feed

This release

0.3.5 This release

1 release file

0.3.4

1 release file

0.3.3

1 release file

0.3.2

1 release file

0.3.1

1 release file

0.3

1 release file

0.2.1

1 release file

0.2

1 release file

0.1.2

1 release file

0.1.1

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page