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

Ignore PermissionError in netrc_info() #810

Closed
wants to merge 9 commits into from
Closed

Conversation

Jonney
Copy link

@Jonney Jonney commented Feb 10, 2020

I'm running uWSGI, the user is "nobody", the netrc_file should be '~/.netrc'.
But I don't know why, the location trunes out to be '/root/.netrc', so a PermissionError raised, it's better to ignore this error instead of to raise.

I'm running uWSGI, the user is  "nobody", the netrc_file should be '~/.netrc'.
But I don't know why, the location trunes out to be '/root/.netrc', so a PermissionError raised, it's better to ignore this error instead of to raise.
@tomchristie
Copy link
Member

Okay. It's not super clear if it'd be better for us to ignore this, or to raise it, to ensure the user is aware of the issue.

You can disable .netrc handling by using trust_env=False, which would be a workaround in the meantime.

I suppose we should probably follow requests' lead here and silently ignore .netrc in cases where it is malformed or causes any kind of IOError... https://github.com/psf/requests/blob/master/requests/utils.py#L209

The build on this pull request is currently failing due to linter errors - make sure to run scripts/lint to apply black and other linting checks.

Copy link
Member

@florimondmanca florimondmanca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! A couple of suggestions from me.

httpx/_utils.py Show resolved Hide resolved
httpx/_utils.py Show resolved Hide resolved
@florimondmanca
Copy link
Member

@Jonney Also, were you able to debug this by using the netrc module directly in a REPL? There might be something set that would make ~ resolve to the root user (although that seems unlikely).

@Jonney
Copy link
Author

Jonney commented Feb 11, 2020

You can disable .netrc handling by using trust_env=False, which would be a workaround in the meantime.

It's ugly to use trust_env=False every time, if so, I want to use Requests instead of httpx

@StephenBrown2
Copy link
Contributor

StephenBrown2 commented Feb 11, 2020

It's ugly to use trust_env=False every time.

Yes, it is. You can use a Client/AsyncClient instance, where trust_env can be set on the client itself, rather that on the request methods:

client = httpx.Client(trust_env=False)
response = client.get('https://example.org')
async with httpx.AsyncClient(trust_env=False) as client:
    response = await client.get('https://example.org')

if so, I want to use Requests instead of httpx

Also, that suggestion was meant as a workaround, not a permanent solution.

ignore (netrc.NetrcParseError, IOError, PermissionError)
httpx/_utils.py Outdated Show resolved Hide resolved
Co-Authored-By: Stephen Brown II <[email protected]>
Copy link
Member

@florimondmanca florimondmanca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're almost there! A suggestion to simplify things a bit.

Note that the CI build is failing due to a missing type annotation on raise_errors, but dropping this parameter should make the lint error go away too. :-)

httpx/_utils.py Outdated Show resolved Hide resolved
@florimondmanca florimondmanca added the user-experience Ensuring that users have a good experience using the library label Mar 28, 2020
Copy link
Member

@tomchristie tomchristie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@tomchristie tomchristie added this to the v0.14 milestone Jul 30, 2020
@tomchristie
Copy link
Member

Thanks so much! Now closed, see #1104

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
user-experience Ensuring that users have a good experience using the library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants