Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用sqlalchemy和psycogp2将数据帧推送到postgres_Python_Python 2.7_Postgresql - Fatal编程技术网

Python 使用sqlalchemy和psycogp2将数据帧推送到postgres

Python 使用sqlalchemy和psycogp2将数据帧推送到postgres,python,python-2.7,postgresql,Python,Python 2.7,Postgresql,我正在尝试将数据帧写入postgres。因为DBAPI使用的是psycogp2 localconn='postgresql+psycopg2://postgres/PSWD@localhost:5432/localPG' localEng=engine.create_engine(localconn) df.to_sql("DUMMY", localEng) 但是它的抛出错误(psycopg2.OperationalError)无法将主机名postgres转换为地址:名称或服务未知 local

我正在尝试将数据帧写入postgres。因为DBAPI使用的是psycogp2

localconn='postgresql+psycopg2://postgres/PSWD@localhost:5432/localPG'
localEng=engine.create_engine(localconn)
df.to_sql("DUMMY", localEng)
但是它的抛出错误
(psycopg2.OperationalError)无法将主机名postgres转换为地址:名称或服务未知

localPG是数据库名称


我哪里做错了?

您编写的格式错误,请使用以下格式:

localEng = create_engine('postgresql+psycopg2://[user]:[pass]@[host]:[port]/[schema]', echo=False)

当然,您应该用等效的数据库凭据替换括号中的每个参数。

非常感谢@rachid。我找了很多。。到处都是我使用的格式。不管怎么说,这真的很有帮助。