-
Notifications
You must be signed in to change notification settings - Fork 144
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
special characters on password gives db error #566
Comments
I am having this exact same issue -- have tried several versions of connectorx and polars, but cannot successfully connect to a redshift database. I get an identical error, though I don't have a "(" in my password -- I have a "[". If I try using cx.read_sql instead of pl.read_database_uri, I get the below error message regardless of which type of dataframe I set as the return_type (and I do have pandas installed). RuntimeError Traceback (most recent call last) C:\ProgramData\Anaconda3\lib\site-packages\connectorx_init_.py in read_sql(conn, query, return_type, protocol, partition_on, partition_range, partition_num, index_col) RuntimeError: db error: ERROR: syntax error at or near "(" |
The raised exception lives in Polars, https://github.com/pola-rs/polars/blob/835d1981dd13b84f466b4bb3ae75e0ea347f8c4e/py-polars/polars/io/database/_utils.py#L78 but I cannot find where it comes from (the connector-x section)
import connectorx
import urllib.parse
password = '·$)(%·!"$%("·$(%="!![[][·$%#("·/$%!"($&'
cn = connectorx.read_sql(f'postgres://postgres:{urllib.parse.quote_plus(password)}@localhost:5432',
'SELECT 1;') Works fine. |
my solution: import connectorx as cx
from urllib.parse import quote_plus
pwd = quote_plus('mypassword##')
SQLALCHEMY_GAUSSDB_PROD_CONNECT_STR = f'postgresql://myusername:{pwd}@xxx:xxx/xxx' # not working
SQLALCHEMY_GAUSSDB_PROD_CONNECT_STR = f'redshift://myusername:{pwd}@xxx:xxx/xxx' # working!
sql = "SELECT 1 FROM dual;"
start = time.time()
try:
result = cx.read_sql(SQLALCHEMY_GAUSSDB_PROD_CONNECT_STR, sql)
logger.warning(len(result))
except Exception as e:
print(f"查询失败: {e}") But I do not know if the server has limit this connection. My database is GAUSSDB |
What language are you using?
Python
What version are you using?
0.3.1
What database are you using?
PostgreSQL
What dataframe are you using?
Arrow / Polars
Can you describe your bug?
I have both "#" and "(" characters in my credentials. From the other bug reports (#319), it looks like
urllib.parse.quote_plus
helps with the "#". But the "(" is now throwing "RuntimeError: db error: ERROR: syntax error at or near '('". The parenthesis is nowhere else except in my credentials.It works fine with
sqlalchemy
. Currently usingpolars
but doesn't seem to be on the polars side since the error gets thrown at thecx.read_sql()
portion.What are the steps to reproduce the behavior?
See example query.
Database setup if the error only happens on specific data or data type
Example query / code
What is the error?
The text was updated successfully, but these errors were encountered: