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

import in hooks definde in env/envfile doesn't work #33

Open
bmlynarczyk-lingaro opened this issue Apr 27, 2021 · 2 comments
Open

import in hooks definde in env/envfile doesn't work #33

bmlynarczyk-lingaro opened this issue Apr 27, 2021 · 2 comments

Comments

@bmlynarczyk-lingaro
Copy link

bmlynarczyk-lingaro commented Apr 27, 2021

Windows 10 Pro/19042.928
Sublime Text 4/Build 4102

import in hooks defined in env/envfile doesn't work
request:

###env
import json

class TokenAuth:

    def __call__(self, r, stream, cert, timeout, verify, proxies):
        json.loads('{"a":"a"}')
###env

requests.post('https://wp.pl', hooks={'response': TokenAuth()})

console output:

error: requests.post('https://wp.pl', hooks={'response': TokenAuth()})
Other Error: 'NoneType' object has no attribute 'loads'
@kylebebak
Copy link
Owner

kylebebak commented May 12, 2021

Thanks for filing this issue. Try this:

###env

class TokenAuth:

    def __call__(self, r, stream, cert, timeout, verify, proxies):
        import json
        json.loads('{"a":"a"}')
###env

requests.post('https://wp.pl', hooks={'response': TokenAuth()})

This is obviously not ideal. Something about how the env dict is built is preventing the import json statement from having any effect, and not being able to import certain modules from the standard library is bad

When I have some time I'll try to figure this out. I noticed that this works, so we can import other modules from the standard library without trouble. Nvm, zlib below is also None

###env
import zlib


class TokenAuth:

    def __call__(self, r, stream, cert, timeout, verify, proxies):
        import json
        print(zlib)
        json.loads('{"a":"a"}')
###env

requests.post('https://wp.pl', hooks={'response': TokenAuth()})

@bmlynarczyk-lingaro
Copy link
Author

bmlynarczyk-lingaro commented May 12, 2021

Thank you @kylebebak! Workaround works as you write above. But importing others modules doesn't work as well. Please look into console output, in mine there is None when zlib is printed. So this is same behavior like in case of json, but in this situation any method isn't invoked on zlib so error doesn't appear during request sending.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants