1

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}]'

しかし、Pycurl を使用して Python スクリプトで同じことをしようとすると、認証エラーが発生します。ここで何が間違っているのかわかりません。

c = pycurl.Curl()
c.setopt(pycurl.URL,url)
c.setopt(pycurl.HTTPHEADER, ['Authorization: Bearer ' + token])
c.setopt(pycurl.HTTPHEADER, ['Content-Type: application/json', 'Accept: application/json'])
data = json.dumps({"id": rid, "locked": False })
c.setopt(pycurl.CUSTOMREQUEST, "PUT")
c.setopt(pycurl.POSTFIELDS,data)
c.setopt(pycurl.POSTFIELDSIZE, len(data))
c.setopt(pycurl.VERBOSE, 1)
c.perform()
c.close()

エラーが発生します:

* 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を使用している間に)何ができるか、または他の回避策を提案できれば素晴らしいでしょう! 助けてください!ありがとう!

4

1 に答える 1