Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not place headers=headers as dict, error ValueError: too many values to unpack (expected 2) #3

Open
MarkBone opened this issue Jun 29, 2021 · 0 comments

Comments

@MarkBone
Copy link

solved Adding .items() on line 29

import requests
from urllib.parse import urlparse


class CFProxy:
    TOKEN_HEADER = 'Px-Token'
    TOKEN_VALUE = 'mysecuretoken'
    HOST_HEADER = 'Px-Host'
    IP_HEADER = 'Px-IP'

    def __init__(self, proxy_host, ua, fake_ip, proxy=None):
        self.session = requests.Session()
        self.session.proxies.update({'https': proxy,
                                     'http': proxy})
        self.session.headers.update({'User-Agent': ua,
                                     self.TOKEN_HEADER: self.TOKEN_VALUE})
        self.proxy_host = proxy_host
        self.fake_ip = fake_ip

    def get(self, url, **kwargs):
        return self.request('GET', url, **kwargs)

    def post(self, url, **kwargs):
        return self.request('POST', url, **kwargs)

    def request(self, method, url, **kwargs):
        # Gestion des headers
        if 'headers' in kwargs:
            for k, v in kwargs.get('headers').items():
                self.session.headers.update({k: v})
            kwargs.pop('headers')
        parsed_uri = urlparse(url)
        self.session.headers.update({self.HOST_HEADER: parsed_uri.hostname})
        self.session.headers.update({self.IP_HEADER: self.fake_ip})
        proxyfied_url = '{0}://{1}{2}'.format(parsed_uri.scheme, self.proxy_host, parsed_uri.path)
        return self.session.request(method, proxyfied_url, **kwargs)

@MarkBone MarkBone changed the title Could not place headers=headers as dict Could not place headers=headers as dict, error ValueError: too many values to unpack (expected 2) Jun 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant