0

私のアカウントには「account_capabilities」があります: ["EMPLOYEE_MANAGEMENT","TIMECARD_MANAGEMENT"]

与えられた Python サンプル (Python 3 用に変更したもの) を使用して、API から売上データを取得することができました。

私はPython 3を使用しています。コードフラグメントは次のとおりです。


#!/usr/bin/python
import http.client, urllib.parse, json

# All requests to the Connect API require an access token
# in an Authorization header. Specify yours here.
access_token = '...'

# In addition to an Authorization header, requests to the Connect API should
# include the indicated Accept and Content-Type headers.
request_headers = {'Authorization': 'Bearer ' + access_token,
                   'Accept':        'application/json',
                   'Content-Type':  'application/json'}

# Send the request to the List Payments endpoint and obtain the response.
connection = http.client.HTTPSConnection('connect.squareup.com')
request_path = 'v1/me/timecards'
connection.request('GET', request_path, '', request_headers)
response = connection.getresponse()

# Convert the returned JSON body into an array of payments you can work with.
payments = json.loads(response.read().decode(encoding='UTF-8'))

# Pretty-print the payments array.
print(json.dumps(payments, indent=2, separators=(',',': ')))

結果:

Microsoft Windows [Version 10.0.10586]
(c) 2015 Microsoft Corporation. All rights reserved.

C:\Users\Thys>cd \Fernleaf

C:\Fernleaf>python fragment.py
Traceback (most recent call last):
  File "fragment.py", line 18, in <module>
    response = connection.getresponse()
  File "C:\Users\Thys\AppData\Local\Programs\Python\Python35\lib\http\client.py", line 1174, in getresponse
    response.begin()
  File "C:\Users\Thys\AppData\Local\Programs\Python\Python35\lib\http\client.py", line 282, in begin
    version, status, reason = self._read_status()
  File "C:\Users\Thys\AppData\Local\Programs\Python\Python35\lib\http\client.py", line 251, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response

C:\Fernleaf>
4

1 に答える 1

0

後で試したところ、エンドポイントがタイムアウトしなくなり、権限エラーが発生しました。従業員 API を使用するには、Square に承認をリクエストする必要があるようです。タイムアウトになった理由はわかりませんが、現在はエラーで応答しています。

于 2015-12-30T23:01:26.580 に答える