Curl命令适用于smartsh,但pycurl命令不适用于smartsh

2024-05-13 18:30:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我能够使用Curl命令成功更新smartsheet:

curl https://api.smartsheet.com/2.0/sheets/sheetID/rows \
> -H "Authorization: Bearer token" \
> -H "Content-Type: application/json" \
> -X PUT \
> -d '[{"id": rid, "locked" : false}]'

但是,当我试图在python脚本中使用Pycurl执行同样的操作时:我得到了授权错误。我不知道我做错了什么。在

^{pr2}$

我得到一个错误:

* About to connect() to api.smartsheet.com port 443 (#0)
*   Trying 198.101.138.130...
* Connected to api.smartsheet.com (198.101.138.130) port 443 (#0)
* Initializing NSS with certpath: sql:/etc/pki/nssdb
*   CAfile: /etc/pki/tls/certs/ca-bundle.crt
  CApath: none
* SSL connection using TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA
* Server certificate:
*   subject: CN=api.smartsheet.com,O="Smartsheet.com, Inc.",L=Bellevue,ST=Washington,C=US,serialNumber=6#####7,businessCategory=Private Organization,incorporationState=Washington,incorporationCountry=US
*   start date: Jul 09 00:00:00 2015 GMT
*   expire date: Jul 08 23:59:59 2017 GMT
*   common name: api.smartsheet.com
*   issuer: CN=Symantec Class 3 EV SSL CA - G3,OU=Symantec Trust Network,O=Symantec Corporation,C=US
> POST /2.0/sheets/sheetid/rows HTTP/1.1
User-Agent: PycURL/7.29.0
Host: api.smartsheet.com
Content-Type: application/json
Accept: application/json
Content-Length: 40

* upload completely sent off: 40 out of 40 bytes
< HTTP/1.1 403 Forbidden
< Date: Mon, 15 Aug 2016 15:17:55 GMT
< Content-Type: application/json;charset=UTF-8
< Content-Length: 116
< Connection: close
< 
{
  "errorCode" : 1004,
  "message" : "You are not authorized to perform this action.",
  "refId" : "za6gmwnreg78"
* Closing connection 0
}403

我不知道怎么了。如果有人能建议可以做什么(同时仍然使用pycurl)或其他任何解决方法,那就太好了!请帮忙!谢谢!在


Tags: tocomapijsonapplicationporttype错误
1条回答
网友
1楼 · 发布于 2024-05-13 18:30:16

我认为这个问题是由您两次调用c.setopt(pycurl.HTTPHEADER, ...)引起的,第二次调用覆盖了第一次调用中的auth令牌集。在

尝试将两个c.setopt调用替换为以下内容:

c.setopt(pycurl.HTTPHEADER, ['Authorization: Bearer ' + token, 'Content-Type: application/json', 'Accept: application/json'])

相关问题 更多 >