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

KeyError: 'headers' at file reqs.py:323 [Possible solution suggested] #176

Open
JimKarvo opened this issue Aug 13, 2024 · 0 comments
Open

Comments

@JimKarvo
Copy link

JimKarvo commented Aug 13, 2024

Hello,

the following code:

payload = {'var': 'true'}
response = request.post("https://mysite.com", data=payload, timeout=10)

produces the following error:

File "/usr/local/lib/python3.11/dist-packages/botasaurus_requests/reqs.py", line 365, in post
    fix_headers(kwargs)
    │           └ {'data': {'var': 'true'}, 'timeout': 10, 'allow_redirects': True, 'browser': 'firefox', 'proxy': 'http://x.x.x.x:xxxx'}
    └ <function fix_headers at 0x7f9c11eff600>
  File "/usr/local/lib/python3.11/dist-packages/botasaurus_requests/reqs.py", line 323, in fix_headers
    if isinstance(kwargs['headers'], dict):
                  └ {'data': {'var': 'true'}, 'timeout': 10, 'allow_redirects': True, 'browser': 'firefox', 'proxy': 'http://[72.10.160.172:16327'](x.x.x.x:xxxx')}

Seems like the code here, is not checks if the headers exists, look like it is mandantory to fil them. If i comment out the code, the botasaurus is working.

File: botasaurus_requests/reqs.py
Line: 323

    if isinstance(kwargs['headers'], dict):
        # fix bug for ints not working
        for key, value in kwargs['headers'].items():
            # if isinstance(kwargs['headers'], int):
            
            kwargs['headers'][key] = str(value)

I think that the problem will be solved if we use the following:

headers = kwargs.get('headers')
if isinstance(headers, dict):

or:

if 'headers' in kwargs and isinstance(kwargs['headers'], dict):
@JimKarvo JimKarvo changed the title KeyError: 'headers' KeyError: 'headers' at file reqs.py:323 [Possible solution suggested] Aug 13, 2024
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