繁体   English   中英

如何找到新记录的 ID? Python、request、postgresql、curl、创建记录和答案

[英]How can I find ID of new record? Python, request, postgresql, curl, create record and answer

如何获取我的代码的新记录 ID:

a = requests.post(url_post, headers=headers, data=new_record)

print(f"status code: {a.status_code}\ntext: {a.text}\nrequest: {a.request}\nheader: {a.headers}\n"
              f"content: {a.content}\nraw: {a.raw}\nencoding: {a.encoding}\n"
              f"json: -> Exception TYPE: <class 'simplejson.errors.JSONDecodeError'>\n"
              f"reason: {a.reason}\n"
              f"raise for status: {a.raise_for_status()}\n"
              f"links: {a.links}\n"
              f"history: {a.history}\n"
              f"cookies: {a.cookies}\n"
              f"elapsed: {a.elapsed}\n"
              f"next: {a.next}")

我得到什么:

status code: 201
text: 
request: <PreparedRequest [POST]>
header: {'Transfer-Encoding': 'chunked', 'Date': 'Wed, 20 Jul 2022 09:14:40 GMT', 'Server': 'postgrest/9.0.1.20220717 (pre-release)', 'Content-Range': '*/*'}
content: b''
raw: <urllib3.response.HTTPResponse object at 0x7f3eb9a2e6d0> 
encoding: None
json: -> Exception TYPE: <class 'simplejson.errors.JSONDecodeError'>
reason: Created
raise for status: None
links: {}
history: []
cookies: <RequestsCookieJar[]>
elapsed: 0:00:00.001559
next: None

我是新来的,请不要对我生气。 我正在尝试以正确的方式写作。 感谢您的耐心等待。

headers = {'Authorization': self.__token,
                   'accept': 'application/json',
                   'Prefer': 'return=representation'
                   }

它有助于获得更多信息:

'首选':'return=representation'

解释链接:http: //postgrest.org/en/v5.2/api.html#insertions-updates

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM