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

db_url does not handle '#' in password? #55

Closed
lisac opened this issue Nov 12, 2015 · 3 comments
Closed

db_url does not handle '#' in password? #55

lisac opened this issue Nov 12, 2015 · 3 comments
Labels
bug Something isn't working

Comments

@lisac
Copy link

lisac commented Nov 12, 2015

I'm trying to configure a database password that happens to contain a #. Is that character not supported in this package's processing of the database url? When I alter the test_postgres_parsing in test.py so that the password contains that character, eg wegauwhgeuioweg --> weg#auwhgeuioweg, the test encounters this error:

ERROR: test_postgres_parsing (environ.test.DatabaseTestSuite)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "c:\projects\django-environ\environ\test.py", line 241, in test_postgres_parsing
    url = Env.db_url_config(url)
  File "c:\projects\django-environ\environ\environ.py", line 371, in db_url_config
    'PORT': _cast_int(url.port),
  File "C:\Python27\Lib\urlparse.py", line 113, in port
    port = int(port, 10)
ValueError: invalid literal for int() with base 10: 'weg'

I've found that other special chars, such as these: }{)(}|!\^><; can be embedded in the database password and not break the test. For example, when I alter the password from wegauwhgeuioweg to :wegauw}{)(}|!\^><;hgeuioweg on lines 238 and 245 of the test case in test.py, no tests fail.

My environment is python 2.7.10.

Summary: Is it true that a # included in the db password will corrupt the db url?

@joke2k
Copy link
Owner

joke2k commented Dec 25, 2015

Some characters must be encoded to avoid beaking the url parsing.
See #48

@joke2k
Copy link
Owner

joke2k commented Nov 13, 2016

Fixed with #69
thank you

@joke2k joke2k closed this as completed Nov 13, 2016
@codeasashu
Copy link

This is still issue in 0.4.5

import os
import environ

os.environ['a'] = 'mysql://engineuser:i!kkGhs#$j57@127.0.0.1:3306/mydb'
env.db('a')

url ParseResult(scheme='mysql', netloc='engineuser:i!)(iLisk', path='', params='', query='', fragment='$js7@10.0.0.80:3306/myoperator_test')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/var/app/python/micro_api/user-availability-api/venv/lib/python3.6/site-packages/environ/environ.py", line 204, in db_url
    return self.db_url_config(self.get_value(var, default=default), engine=engine)
  File "/var/app/python/micro_api/user-availability-api/venv/lib/python3.6/site-packages/environ/environ.py", line 403, in db_url_config
    'PORT': _cast_int(url.port) or '',
  File "/usr/lib/python3.6/urllib/parse.py", line 169, in port
    port = int(port, 10)
ValueError: invalid literal for int() with base 10: 'i!kkGhs'

jtriley added a commit to nerc-project/coldfront-nerc that referenced this issue Nov 1, 2021
This is needed to handle passwords with characters that are not
URL-safe due to the fact that django-environ parses the DB string using
urlparse. Without this we'd have to urlencode the password.

See joke2k/django-environ#55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants