jazzband / dj-database-url

Use Database URLs in your Django Application.
https://pypi.org/project/dj-database-url/
BSD 3-Clause "New" or "Revised" License
1.48k stars 205 forks source link

question marks in database passwords break in unexpected ways #70

Closed tobiasmcnulty closed 6 years ago

tobiasmcnulty commented 8 years ago

I am getting the following error because I have a ? after e5 in my DB password:

[Sat Jun 25 06:44:00.793929 2016] [:error] [pid 3529] [remote 127.0.0.1:42186]   File "/opt/python/current/app/foo/settings.py", line 63, in <module>
[Sat Jun 25 06:44:00.793943 2016] [:error] [pid 3529] [remote 127.0.0.1:42186]     'default': dj_database_url.config(default='postgres:///foo'),
[Sat Jun 25 06:44:00.793960 2016] [:error] [pid 3529] [remote 127.0.0.1:42186]   File "/opt/python/run/venv/lib/python3.4/site-packages/dj_database_url.py", line 46, in config
[Sat Jun 25 06:44:00.793964 2016] [:error] [pid 3529] [remote 127.0.0.1:42186]     config = parse(s, engine)
[Sat Jun 25 06:44:00.793979 2016] [:error] [pid 3529] [remote 127.0.0.1:42186]   File "/opt/python/run/venv/lib/python3.4/site-packages/dj_database_url.py", line 84, in parse
[Sat Jun 25 06:44:00.793982 2016] [:error] [pid 3529] [remote 127.0.0.1:42186]     'PORT': url.port or '',
[Sat Jun 25 06:44:00.793999 2016] [:error] [pid 3529] [remote 127.0.0.1:42186]   File "/usr/lib64/python3.4/urllib/parse.py", line 156, in port
[Sat Jun 25 06:44:00.794002 2016] [:error] [pid 3529] [remote 127.0.0.1:42186]     port = int(port, 10)
[Sat Jun 25 06:44:00.794020 2016] [:error] [pid 3529] [remote 127.0.0.1:42186] ValueError: invalid literal for int() with base 10: 'e5'

It would be nice to support question marks in passwords or at least display a more helpful error message when this occurs.

kennethreitz commented 8 years ago

You should be percent encoding these.

nikita-kuznetsov commented 8 years ago

same with dash (#) asdafsf#asd