Skip to content

ValueError: invalid literal for int() with base 10 #429

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

Closed
marshallford opened this issue Apr 3, 2019 · 10 comments
Closed

ValueError: invalid literal for int() with base 10 #429

marshallford opened this issue Apr 3, 2019 · 10 comments

Comments

@marshallford
Copy link

  • asyncpg version: 0.18.3
  • PostgreSQL version: PostgreSQL 10.5, compiled by Visual C++ build 1800, 64-bit
  • Do you use a PostgreSQL SaaS? If so, which? Can you reproduce
    the issue with a local PostgreSQL install?
    : Azure, haven't tried to reproduce with a local PG
  • Python version: 3.6.7
  • Platform: WSL - Ubuntu 18.04
  • Do you use pgbouncer?: no
  • Did you install asyncpg with pip?: yes
  • If you built asyncpg locally, which version of Cython did you use?: N/A
  • Can the issue be reproduced under both asyncio and uvloop?: Will try after submitting issue.
await asyncpg.connect(dsn="postgres://user@some-azure-uid:[email protected]:5432/database")

returns:

ValueError: invalid literal for int() with base 10: '[email protected]:5432'

Obviously this isn't my actual hostname or password. I have tried removing the port (:5432) thinking that it is the only part that would be parsed as an int.

I'm sure this is just a silly mistake on my end that I can't see. Thanks.

@elprans
Copy link
Member

elprans commented Apr 3, 2019

Looks like #418. You’ve got @ in your username which throws off the DSN parser. Try passing it as a url-eacaped query argument: ?user=...

@marshallford
Copy link
Author

I assumed libpq's parsing supported this syntax because I've run into the error: Please check the Username and retry connection. The Username should be in <username@hostname> format. I'll give that a shot.

@elprans
Copy link
Member

elprans commented Apr 3, 2019

That error and the source code suggest that libpq doesn't actually support literal @ in the username.

@marshallford
Copy link
Author

marshallford commented Apr 3, 2019

I got that error when not including the literal @ in a username so I am bit confused by your reply. In addition I tried encoding @ (as %40) and got back the same error. Lastly, I've already tried both the literal and encoded @ in the query argument and ran into the same error. I must be missing something. thanks.

@elprans
Copy link
Member

elprans commented Apr 3, 2019

asyncpg parses this correctly for me: postgresql://some-azure-uid.postgres.database.azure.com:5432/database?user=user%40some-azure-uid&password=password

@marshallford
Copy link
Author

Thanks for your help. I mistakenly used ? instead of & for key value separators. 😫

@KrunchMuffin
Copy link

KrunchMuffin commented Aug 19, 2020

asyncpg parses this correctly for me: postgresql://some-azure-uid.postgres.database.azure.com:5432/database?user=user%40some-azure-uid&password=password

is this the proper way of connecting? not this?
postgresql://user@name:[email protected]:5432/database?sslmode=require

update:
wholly sheet, it works! I have been dealing with trying to connect for hours over 2 days with the other string.

@elprans
Copy link
Member

elprans commented Aug 20, 2020

user@name

The correct way is to use urllib.parse.quote to quote all parts of the DSN that may contain characters, which are not URL safe (such as @ or :).

@KrunchMuffin
Copy link

That's fine, but putting it as username:password with or without quote does not yield a successful start up.

@elprans
Copy link
Member

elprans commented Aug 20, 2020

To clarify, both username and password must be quoted individually and then concatenated using :. There are lots of tests for this behavior.

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

3 participants