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

当我稍后尝试时,端点不再超时,并且我收到了权限错误。看来您需要向 Square 请求授权才能使用员工 api。不知道他们为什么超时,但他们现在响应错误。

于 2015-12-30T23:01:26.580 回答