peewee 상용 기교

5305 단어 errorPython3

1. 데이터베이스 링크


일반 링크는 dburl 문자열을 통해 데이터베이스를 지정합니다
from playhouse.db_url import connect
from playhouse.reflection import generate_models

dburl = "mysql+pool://root:A2xIX@[email protected]:3306/recommend_features?max_connections=3&stale_timeout=300"

table_name = "cartoon_sta"
db = connect(dburl)
models = generate_models(db)
Table = models.get(table_name)

result = Table.select(Table.cid)
cid_online = [i.cid for i in result]
db.close()

비밀번호에'!'+숫자, 예를 들어 dburl = "mysql+pool://root:X!5#@xxx^[email protected]:3306/comic?max_connections=3&stale_timeout=300”
An error was encountered:
invalid literal for int() with base 10: 'X!5'
Traceback (most recent call last):
  File "/root/miniconda3/lib/python3.7/site-packages/playhouse/db_url.py", line 87, in connect
    connect_kwargs = parseresult_to_dict(parsed, unquote_password)
  File "/root/miniconda3/lib/python3.7/site-packages/playhouse/db_url.py", line 51, in parseresult_to_dict
    if parsed.port:
  File "/root/miniconda3/lib/python3.7/urllib/parse.py", line 169, in port
    port = int(port, 10)
ValueError: invalid literal for int() with base 10: 'X!5'

해결 방법
from peewee import MySQLDatabase
db = MySQLDatabase('recommend_features', **{
                          'host': 'rm-xxxxxxxxxxx.mysql.rds.aliyuncs.com', 
                          'port': 3306, 
                          'user': 'root', 
                          'password': 'X!5#@xxx^aaaNyyy'})
table_name = "cartoon_topic"
models = generate_models(db)
Table = models.get(table_name)

db.close()

좋은 웹페이지 즐겨찾기