{"action":"opened","issue":{"url":"https://api.github.com/repos/waditu/tushare/issues/692","repository_url":"https://api.github.com/repos/waditu/tushare","labels_url":"https://api.github.com/repos/waditu/tushare/issues/692/labels{/name}","comments_url":"https://api.github.com/repos/waditu/tushare/issues/692/comments","events_url":"https://api.github.com/repos/waditu/tushare/issues/692/events","html_url":"https://github.com/waditu/tushare/issues/692","id":337027943,"node_id":"MDU6SXNzdWUzMzcwMjc5NDM=","number":692,"title":"Python3数据写入mysql失败:AttributeError: 'NoneType' object has no attribute 'replace'","user":{"login":"vanabel","id":4273353,"node_id":"MDQ6VXNlcjQyNzMzNTM=","avatar_url":"https://avatars0.githubusercontent.com/u/4273353?v=4","gravatar_id":"","url":"https://api.github.com/users/vanabel","html_url":"https://github.com/vanabel","followers_url":"https://api.github.com/users/vanabel/followers","following_url":"https://api.github.com/users/vanabel/following{/other_user}","gists_url":"https://api.github.com/users/vanabel/gists{/gist_id}","starred_url":"https://api.github.com/users/vanabel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vanabel/subscriptions","organizations_url":"https://api.github.com/users/vanabel/orgs","repos_url":"https://api.github.com/users/vanabel/repos","events_url":"https://api.github.com/users/vanabel/events{/privacy}","received_events_url":"https://api.github.com/users/vanabel/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-06-29T14:48:55Z","updated_at":"2018-06-29T14:48:55Z","closed_at":null,"author_association":"NONE","body":"测试代码:\r\n```python\r\n#!/usr/bin/python3\r\n#-*- coding: utf-8 -*-\r\nfrom sqlalchemy import create_engine\r\nimport tushare as ts\r\n\r\nengine=create_engine(\"mysql+pymysql://root:test@localhost:3306\",echo=True)\r\nengine.execute(\"CREATE DATABASE IF NOT EXISTS tushare DEFAULT CHARSET utf8 COLLATE utf8_general_ci\")\r\nengine.execute(\"USE tushare\")\r\n\r\ndata=ts.get_h_data('000001', start='2017-06-29', end='2017-06-29')\r\nprint(data)\r\ndata.to_sql('SHS_index', engine, if_exists='append')\r\n```\r\n实际运行后, 输出\r\n>            open  high  close   low      volume       amount\r\n>date\r\n2017-06-29  9.13  9.15   9.13  9.07  48880457.0  459810416.0\r\n\r\n数据成功写入到了mysql数据库。 这可以通过\r\n```mysql\r\nuse tushare;\r\nselect * from SHS_index;\r\n```\r\n查看:\r\n> MariaDB [tushare]> select * from SHS_index;\r\n+---------------------+------+------+-------+------+----------+-----------+\r\n| date                | open | high | close | low  | volume   | amount    |\r\n+---------------------+------+------+-------+------+----------+-----------+\r\n| 2017-06-29 00:00:00 | 9.13 | 9.15 |  9.13 | 9.07 | 48880457 | 459810416 |\r\n+---------------------+------+------+-------+------+----------+-----------+\r\n1 row in set (0.00 sec)\r\n\r\n但是, python却报告错误：\r\n>File \"/usr/lib/python3.6/site-packages/sqlalchemy/sql/compiler.py\", line 3022, in _escape_identifier\r\n    value = value.replace(self.escape_quote, self.escape_to_quote)\r\nAttributeError: 'NoneType' object has no attribute 'replace'\r\n\r\n我怀疑是数据格式的问题？ 与官方教程不同的是我的引擎使用了`mysql+pymysql`, 官方的`mysql`报错(cygwin):\r\n>ModuleNotFoundError: No module named 'MySQLdb'\r\n\r\n这样, 当我想连续写入数据时, 程序会中断运行。\r\n"}}
{"actor":{"display_login":"vanabel"}}