Skip to main content

Add custom proxy headers to HTTPS requests in Scrapy

Project description

Scrapy Proxy Headers

The scrapy-proxy-headers package is designed for adding proxy headers to HTTPS requests in Scrapy.

In normal usage, custom headers put in request.headers cannot be read by a proxy when you make a HTTPS request, because the headers are encrypted and passed through the proxy tunnel, along with the rest of the request body. You can read more about this at Proxy Server Requests over HTTPS.

Because Scrapy does not have a good way to pass custom headers to a proxy when you make HTTPS requests, we at ProxyMesh made this extension to support our customers that use Scrapy and want to use custom headers to control our proxy behavior. But this extension can work for handling custom headers through any proxy.

Installation

To use this extension, do the following:

  1. pip install scrapy-proxy-headers
  2. In your Scrapy settings.py, add the following:
DOWNLOAD_HANDLERS = {
  "https": "scrapy_proxy_headers.HTTP11ProxyDownloadHandler"
}

Usage

When you want make a request with a custom proxy header, instead of using request.headers, use request.meta["proxy_headers"] like this:

request.meta["proxy_headers"] = {"X-ProxyMesh-Country": "US"}

Any response headers that might come from the proxy will be saved in response.headers, as in response.headers["X-ProxyMesh-IP"].

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

scrapy-proxy-headers-0.1.4.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

scrapy_proxy_headers-0.1.4-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file scrapy-proxy-headers-0.1.4.tar.gz.

File metadata

  • Download URL: scrapy-proxy-headers-0.1.4.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.13

File hashes

Hashes for scrapy-proxy-headers-0.1.4.tar.gz
Algorithm Hash digest
SHA256 683c51f6b017a7f7d83a7e25c52fd9645f2783ddf6308341fc4753acdefaa80a
MD5 31fb499546b57baa613ce700ae2eb5dc
BLAKE2b-256 ee1016a304e38f35d3611f83f316a787899c08bfa3c798913f5efc570ca7fa40

See more details on using hashes here.

File details

Details for the file scrapy_proxy_headers-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for scrapy_proxy_headers-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 a92c26e7ef23b68a64c98498a7a76640b5403e45f7e4c5e76b10fb78f1e922c2
MD5 17deded602ac2edee532d07622a7ff63
BLAKE2b-256 d6c92400487e46828f6128bc1c6b0157bc083da83935bdd172ec31b3779b8a26

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page