擅长:python、mysql、java
<p><strong>澄清</strong></p>
<p>下面的答案被接受了,但是,这并不是解决问题的办法。。。问题是postgresql服务器配置为端口5433,而不是默认端口5432。这样可以解决问题:</p>
<pre><code>connection = psycopg2.connect(database="gps_heatmap", user="postgres", password="1234", host="localhost", port=5433)
</code></pre>
<hr/>
<p><strong>原始答案</strong></p>
<p>尝试将<code>dbname="gps_heatmap"</code>替换为<code>database="gps_heatmap"</code>,因为前者用于连接字符串,后者用于将关键字参数传递给<code>psycopg2.connect()</code>:</p>
<pre><code>connection = psycopg2.connect(database="gps_heatmap", user="postgres", host="localhost", password="1234")
</code></pre>
<p>或者可以使用连接字符串:</p>
<pre><code>connection = psycopg2.connect("dbname=gps_heatmap user=postgres host=localhost password=1234")
</code></pre>