pymysql连接KeyError 255

时间:2018-11-12 15:21:19

标签: python mysql sqlalchemy pymysql

我正在尝试连接Windows Server中托管的MySQL Server。 pymysql和sqlalchemy给我一个Key Error 255错误。

来自pymysql连接的错误是

    KeyError                                  Traceback (most recent call last)
<ipython-input-22-2719dd75fa2e> in <module>()
      4     user='LR',
      5     passwd='password',
----> 6     db='Lr_DB'
      7 )

C:\ProgramData\Anaconda3\lib\site-packages\pymysql\__init__.py in Connect(*args, **kwargs)
     86     """
     87     from .connections import Connection
---> 88     return Connection(*args, **kwargs)
     89 
     90 from pymysql import connections as _orig_conn

C:\ProgramData\Anaconda3\lib\site-packages\pymysql\connections.py in __init__(self, host, user, password, database, port, unix_socket, charset, sql_mode, read_default_file, conv, use_unicode, client_flag, cursorclass, init_command, connect_timeout, ssl, read_default_group, compress, named_pipe, no_delay, autocommit, db, passwd, local_infile)
    642         self.sql_mode = sql_mode
    643         self.init_command = init_command
--> 644         self._connect()
    645 
    646     def close(self):

C:\ProgramData\Anaconda3\lib\site-packages\pymysql\connections.py in _connect(self)
    835             self.socket = sock
    836             self._rfile = _makefile(sock, 'rb')
--> 837             self._get_server_information()
    838             self._request_authentication()
    839 

C:\ProgramData\Anaconda3\lib\site-packages\pymysql\connections.py in _get_server_information(self)
   1070             i += 6
   1071             self.server_language = lang
-> 1072             self.server_charset = charset_by_id(lang).name
   1073 
   1074             self.server_status = stat

C:\ProgramData\Anaconda3\lib\site-packages\pymysql\charset.py in by_id(self, id)
     32 
     33     def by_id(self, id):
---> 34         return self._by_id[id]
     35 
     36     def by_name(self, name):

KeyError: 255

我甚至尝试按照SO答案的建议在PyMYSQL和sqlalchemy中的连接字符串中设置字符集。

我尝试了来自R和ODBC的连接,它工作正常。

0 个答案:

没有答案