Pymysql Unknow Encoding "latin1" - python

I have experience running pymysql because it always return
the following error
Traceback (most recent call last):
File "synch.py", line 69, in <module>
db = pymysql.connect(host='localhost',user='root',password='mypassword',db='mytable',charset='utf8')
File "/home/pi/.local/lib/python2.7/site-packages/pymysql/__init__.py", line 94, in Connect
return Connection(*args, **kwargs)
File "/home/pi/.local/lib/python2.7/site-packages/pymysql/connections.py", line 327, in __init__
self.connect()
File "/home/pi/.local/lib/python2.7/site-packages/pymysql/connections.py", line 587, in connect
self._get_server_information()
File "/home/pi/.local/lib/python2.7/site-packages/pymysql/connections.py", line 976, in _get_server_information
self.server_version = data[i:server_end].decode('latin1')
LookupError: unknown encoding: latin1

Related

Python connection with database

I am trying to connect the database mysql to mycode but i don't know what is the problen i have treid many solution but still confuse if any body can help ?
`
e:\hotelManagnment\customer.py:38: DeprecationWarning: ANTIALIAS is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.LANCZOS instead.
img2=img2.resize((100,40),Image.ANTIALIAS)
Traceback (most recent call last):
File "e:\hotelManagnment\customer.py", line 262, in <module>
obj=Cust_Win(root)
File "e:\hotelManagnment\customer.py", line 212, in __init__
self.fetch_data()
File "e:\hotelManagnment\customer.py", line 245, in fetch_data
conn=mysql.connector.connect(host="localhost",username="root",password="",database="managment")
File "C:\Users\hp\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\mysql\connector\pooling.py", line 287, in connect
return MySQLConnection(*args, **kwargs)
File "C:\Users\hp\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\mysql\connector\connection.py", line 137, in __init__
self.connect(**kwargs)
File "C:\Users\hp\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\mysql\connector\abstracts.py", line 1108, in connect
self._open_connection()
File "C:\Users\hp\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\mysql\connector\connection.py", line 544, in _open_connection
self.set_converter_class(self._converter_class)
File "C:\Users\hp\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\mysql\connector\abstracts.py", line 1284, in set_converter_class
self.converter = convclass(charset_name, self._use_unicode)
File "C:\Users\hp\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\mysql\connector\conversion.py", line 136, in __init__
MySQLConverterBase.__init__(self, charset, use_unicode, str_fallback)
File "C:\Users\hp\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\mysql\connector\conversion.py", line 59, in __init__
self.set_charset(charset)
File "C:\Users\hp\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\mysql\connector\conversion.py", line 73, in set_charset
self.charset_id = CharacterSet.get_charset_info(self.charset)[0]
File "C:\Users\hp\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\mysql\connector\constants.py", line 775, in get_charset_info
info = cls.get_default_collation(charset)
File "C:\Users\hp\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\mysql\connector\constants.py", line 746, in get_default_collation
raise ProgrammingError(f"Character set '{charset}' unsupported")
mysql.connector.errors.ProgrammingError: Character set 'utf8' unsupported
`

mysql-connector issue while executing program(bad handshake)

I am getting some bad handshake errors while execution of program
after installing mysql-connector
import mysql.connector as c
con=c.connect(host="localhost",user="root",passwd='tiger',database='employee')
if con.is_connected():
print("success")
else:
print("connectivity issue")
errors
Traceback (most recent call last):
File "C:\Users\Sahil Panhalkar\AppData\Local\Programs\Python\Python310\lib\site-packages\mysql\connector\connection_cext.py", line 268, in _open_connection
self._cmysql.connect(**cnx_kwargs)
_mysql_connector.MySQLInterfaceError: Bad handshake
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\Sahil Panhalkar\Desktop\connectivity.py", line 2, in <module>
con=c.connect(host="localhost",user="root",passwd='tiger',database='employee')
File "C:\Users\Sahil Panhalkar\AppData\Local\Programs\Python\Python310\lib\site-packages\mysql\connector\pooling.py", line 286, in connect
return CMySQLConnection(*args, **kwargs)
File "C:\Users\Sahil Panhalkar\AppData\Local\Programs\Python\Python310\lib\site-packages\mysql\connector\connection_cext.py", line 101, in __init__
self.connect(**kwargs)
File "C:\Users\Sahil Panhalkar\AppData\Local\Programs\Python\Python310\lib\site-packages\mysql\connector\abstracts.py", line 1108, in connect
self._open_connection()
File "C:\Users\Sahil Panhalkar\AppData\Local\Programs\Python\Python310\lib\site-packages\mysql\connector\connection_cext.py", line 273, in _open_connection
raise get_mysql_exception(
mysql.connector.errors.OperationalError: 1043 (08S01): Bad handshake

Can't establish a connection using snowflake-connector-python v1.9

(Asking the following question on behalf of a client)
............
Due to the size of all dependencies snowflake-connector-python is having I had to switch to v1.9 (106Mb total size) and now I'm not able to establish connection, v2.0 is not functioning as well. The only working version is v2.0.1 but it's huge (320Mb total size) comparing to the v1.9.
Traceback (most recent call last):
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/snowflake/connector/ocsp_snowflake.py", line 1131, in validate_by_direct_connection
self.process_ocsp_response(issuer, cert_id, ocsp_response)
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/snowflake/connector/ocsp_asn1crypto.py", line 280, in process_ocsp_response
tbs_response_data)
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/snowflake/connector/ocsp_asn1crypto.py", line 316, in verify_signature
pubkey = cert.public_key.unwrap().dump()
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/asn1crypto/keys.py", line 1065, in unwrap
'asn1crypto.keys.PublicKeyInfo().unwrap() has been removed, '
asn1crypto._errors.APIException: asn1crypto.keys.PublicKeyInfo().unwrap() has been removed, please use oscrypto.asymmetric.PublicKey().unwrap() instead
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/snowflake/connector/network.py", line 790, in _request_exec
auth=SnowflakeAuth(token),
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/botocore/vendored/requests/sessions.py", line 465, in request
resp = self.send(prep, **send_kwargs)
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/botocore/vendored/requests/sessions.py", line 573, in send
r = adapter.send(request, **kwargs)
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/botocore/vendored/requests/adapters.py", line 370, in send
timeout=timeout
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/botocore/vendored/requests/packages/urllib3/connectionpool.py", line 544, in urlopen
body=body, headers=headers)
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/botocore/vendored/requests/packages/urllib3/connectionpool.py", line 341, in _make_request
self._validate_conn(conn)
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/botocore/vendored/requests/packages/urllib3/connectionpool.py", line 761, in _validate_conn
conn.connect()
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/botocore/vendored/requests/packages/urllib3/connection.py", line 238, in connect
ssl_version=resolved_ssl_version)
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/snowflake/connector/ssl_wrap_socket.py", line 395, in ssl_wrap_socket_with_ocsp
).validate(server_hostname, ret.connection)
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/snowflake/connector/ocsp_snowflake.py", line 996, in validate
return self._validate(hostname, cert_data, telemetry_data, do_retry, no_exception)
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/snowflake/connector/ocsp_snowflake.py", line 1002, in _validate
cert_data, telemetry_data, hostname, do_retry=do_retry)
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/snowflake/connector/ocsp_snowflake.py", line 1184, in _validate_certificates_sequential
issuer, subject, telemetry_data, hostname, do_retry=do_retry)
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/snowflake/connector/ocsp_snowflake.py", line 1153, in validate_by_direct_connection
err = self.verify_fail_open(ex, telemetry_data)
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/snowflake/connector/ocsp_snowflake.py", line 1166, in verify_fail_open
if ex_obj.errno is ER_SERVER_CERTIFICATE_REVOKED:
AttributeError: 'APIException' object has no attribute 'errno'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/snowflake/connector/network.py", line 640, in _request_exec_wrapper
**kwargs)
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/snowflake/connector/network.py", line 883, in _request_exec
raise RetryRequest(err)
snowflake.connector.network.RetryRequest: 'APIException' object has no attribute 'errno'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/avinogradov/git/crux/step_function/snowflake_update/test.py", line 25, in <module>
schema=SCHEMA
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/snowflake/connector/__init__.py", line 33, in Connect
return SnowflakeConnection(**kwargs)
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/snowflake/connector/connection.py", line 187, in __init__
self.connect(**kwargs)
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/snowflake/connector/connection.py", line 484, in connect
self.__open_connection()
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/snowflake/connector/connection.py", line 700, in __open_connection
self.__authenticate(auth_instance)
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/snowflake/connector/connection.py", line 931, in __authenticate
session_parameters=self._session_parameters,
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/snowflake/connector/auth.py", line 197, in authenticate
socket_timeout=self._rest._connection.login_timeout)
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/snowflake/connector/network.py", line 521, in _post_request
_include_retry_params=_include_retry_params)
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/snowflake/connector/network.py", line 600, in fetch
**kwargs)
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/snowflake/connector/network.py", line 683, in _request_exec_wrapper
conn, full_url, cause)
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/snowflake/connector/network.py", line 713, in handle_invalid_certificate_error
u'errno': ER_FAILED_TO_REQUEST,
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/snowflake/connector/errors.py", line 100, in errorhandler_wrapper
connection.errorhandler(connection, cursor, errorclass, errorvalue)
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/snowflake/connector/errors.py", line 73, in default_errorhandler
done_format_msg=errorvalue.get(u'done_format_msg'))
snowflake.connector.errors.OperationalError: 250003: Failed to execute request: 'APIException' object has no attribute 'errno'
............
The client is currently able to get around the issue by using the latest version (2.0.1) but to delete pyarrow and numpy (pip uninstall pyarrow numpy) later to reduce dependencies size (these dependencies are used by customers who are on the Private Preview only).
Are there any better recommendations out there?
You are correct that this is an issue that was fixed in v2.0.1. The older versions of the Python connector are failing while validating the certificate using the recently upgraded package of asn1crypto 1.0.0. The workaround is to use asn1crypt 0.24.0.
pip install snowflake-connector-python asn1crypto==0.24.0

Error connecting to PyPy3 multiprocessing remote manager

I am trying to run the remote manager example code from the multiprocessing documentation in pypy3 but I get an error connecting the client.
Traceback (most recent call last):
File "C:/temp/testpypy/mp_client.py", line 7, in <module>
m.connect()
File "C:\Python\pypy3-v6.0.0-win32\lib-python\3\multiprocessing\managers.py", line 455, in connect
conn = Client(self._address, authkey=self._authkey)
File "C:\Python\pypy3-v6.0.0-win32\lib-python\3\multiprocessing\connection.py", line 493, in Client
answer_challenge(c, authkey)
File "C:\Python\pypy3-v6.0.0-win32\lib-python\3\multiprocessing\connection.py", line 732, in answer_challenge
message = connection.recv_bytes(256) # reject large message
File "C:\Python\pypy3-v6.0.0-win32\lib-python\3\multiprocessing\connection.py", line 216, in recv_bytes
buf = self._recv_bytes(maxlength)
File "C:\Python\pypy3-v6.0.0-win32\lib-python\3\multiprocessing\connection.py", line 407, in _recv_bytes
buf = self._recv(4)
File "C:\Python\pypy3-v6.0.0-win32\lib-python\3\multiprocessing\connection.py", line 386, in _recv
buf.write(chunk)
TypeError: 'str' does not support the buffer interface
if I try to connect to it from a CPython interpreter (which is my ultimate goal) I get the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "c:\Python\3.5.4.2\WinPython\python-3.5.4.amd64\lib\multiprocessing\managers.py", line 455, in connect
conn = Client(self._address, authkey=self._authkey)
File "c:\Python\3.5.4.2\WinPython\python-3.5.4.amd64\lib\multiprocessing\connection.py", line 493, in Client
answer_challenge(c, authkey)
File "c:\Python\3.5.4.2\WinPython\python-3.5.4.amd64\lib\multiprocessing\connection.py", line 737, in answer_challenge
response = connection.recv_bytes(256) # reject large message
File "c:\Python\3.5.4.2\WinPython\python-3.5.4.amd64\lib\multiprocessing\connection.py", line 218, in recv_bytes
self._bad_message_length()
File "c:\Python\3.5.4.2\WinPython\python-3.5.4.amd64\lib\multiprocessing\connection.py", line 151, in _bad_message_length
raise OSError("bad message length")
OSError: bad message length
Turns out to be a bug in PyPy3.
Here is the fixed ticket:
https://bitbucket.org/pypy/pypy/issues/2841/remote-multprocessing-issue#comment-45861347

web2py firebird db fails connect

I trying to connect a web2py app to a firebird database in another server.
This is the output message:
Ticket ID
127.0.0.1.2016-01-11.12-27-33.cdefb9f6-3cc5-46ce-85dc-a2a12220e7f6
Failure to connect, tried 5 times:
Traceback (most recent call last): File
"/home/filhofilha/Documents/Deployment/Web2Py/web2py/gluon/packages/dal/pydal/base.py",
line 435, in init self._adapter = ADAPTERSself._dbname
File
"/home/filhofilha/Documents/Deployment/Web2Py/web2py/gluon/packages/dal/pydal/adapters/base.py",
line 53, in call obj = super(AdapterMeta, cls).call(*args,
**kwargs) File "/home/filhofilha/Documents/Deployment/Web2Py/web2py/gluon/packages/dal/pydal/adapters/firebird.py",
line 121, in init if do_connect: self.reconnect() File
"/home/filhofilha/Documents/Deployment/Web2Py/web2py/gluon/packages/dal/pydal/connection.py",
line 105, in reconnect self.connection = f() File
"/home/filhofilha/Documents/Deployment/Web2Py/web2py/gluon/packages/dal/pydal/adapters/firebird.py",
line 119, in connector return self.driver.connect(**driver_args) File
"/home/filhofilha/Documents/Deployment/Web2Py/web2py/gluon/contrib/pypyodbc.py",
line 2434, in init self.connect(connectString, autocommit, ansi,
timeout, unicode_results, readonly) File
"/home/filhofilha/Documents/Deployment/Web2Py/web2py/gluon/contrib/pypyodbc.py",
line 2483, in connect check_success(self, ret) File
"/home/filhofilha/Documents/Deployment/Web2Py/web2py/gluon/contrib/pypyodbc.py",
line 988, in check_success ctrl_err(SQL_HANDLE_DBC, ODBC_obj.dbc_h,
ret, ODBC_obj.ansi) File
"/home/filhofilha/Documents/Deployment/Web2Py/web2py/gluon/contrib/pypyodbc.py",
line 964, in ctrl_err raise Error(state,err_text) Error: (u'IM012',
u'[IM012] [unixODBC][Driver Manager]DRIVER keyword syntax error')
My Code:
dbExternal = DAL('firebird://user:password#localhost/C:\\DB.FDB', migrate_enabled=False)
how can I fix it ?
Thanks
I was missing the python firebird driver. I installed it to correct my problem

Categories