admin管理员组文章数量:1124312
I have a pretty vanilla PostgreSQL installation. I'm trying to use a feature of jsonschematoddl
to create a table(s) from a JSON schema file.
I can load the schema file fine, but my connection to the local PostgreSQL database always fails with a 403 "Forbidden," which I assume is an authentication/authorization issue in my configuration.
I tried connecting with both psycopg2
and sqlalchemy
, but both behave the same. I can connect fine via psql
as both my user and the postgres
user.
I've tried several URI variations to no avail.
I'm clearly overlooking something, so any pointers or suggestions are appreciated.
Here's my python script:
import json
with open('/Users/n123/sauce_device.json') as f:
schema = json.load(f)
pg_uri = 'postgresql://[email protected]:5432/postgres'
# With psycopg2
import psycopg2
conn = psycopg2.connect(pg_uri)
#conn = psycopg2.connect(dbname='postgres', user='n123', host='localhost', password='power')
# OR with sqlalchemy
# from sqlalchemy import create_engine
# conn = create_engine(pg_uri).raw_connection()
from jsonschema2ddl import JSONSchemaToDatabase
translator = JSONSchemaToDatabase(
schema,
root_table_name='sauce_devices',
)
translator.create_tables(conn)
translator.create_links(conn)
translator.analyze(conn)
connit()
Here's the error I get when the script is run:
Traceback (most recent call last):
File "/Users/n123/schema-to-ddl.py", line 18, in <module>
translator = JSONSchemaToDatabase(
^^^^^^^^^^^^^^^^^^^^^
File "/Users/n123/.pyenv/versions/3.12.1/lib/python3.12/site-packages/jsonschema2ddl/translators.py", line 59, in __init__
self._validate_schema()
File "/Users/n123/.pyenv/versions/3.12.1/lib/python3.12/site-packages/jsonschema2ddl/translators.py", line 73, in _validate_schema
metaschema_uri = urlopen(metaschema_uri).url
^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/n123/.pyenv/versions/3.12.1/lib/python3.12/urllib/request.py", line 215, in urlopen
return opener.open(url, data, timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/n123/.pyenv/versions/3.12.1/lib/python3.12/urllib/request.py", line 521, in open
response = meth(req, response)
^^^^^^^^^^^^^^^^^^^
File "/Users/n123/.pyenv/versions/3.12.1/lib/python3.12/urllib/request.py", line 630, in http_response
response = self.parent.error(
^^^^^^^^^^^^^^^^^^
File "/Users/n123/.pyenv/versions/3.12.1/lib/python3.12/urllib/request.py", line 559, in error
return self._call_chain(*args)
^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/n123/.pyenv/versions/3.12.1/lib/python3.12/urllib/request.py", line 492, in _call_chain
result = func(*args)
^^^^^^^^^^^
File "/Users/n123/.pyenv/versions/3.12.1/lib/python3.12/urllib/request.py", line 639, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 403: Forbidden
本文标签:
版权声明:本文标题:PostgreSQL connection problem from a Python script that uses psycopg2. What am I missing? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736603181a1945265.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论