我正在使用LINE Messaging API尝试通过bot推送消息。我已按照https://business.line.me/en/中详细介绍的配置/设置进行操作,并遇到此错误 - 由于以下原因而拒绝访问此API:您的IP地址[23.3.104.4]不允许访问此API。请将您的IP地址添加到IP白名单中的开发中心。”LINE RESTful Messaging API - 错误的IP地址错误
但我已经添加了我的IP在开发者中心的服务器白名单。 的IP错误指示甚至不是我的IP。
下面是Python代码片段:
def line_http(uri, req_body, accessToken, m='post'):
req_headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + accessToken
}
if m=='post':
result = urlfetch.post(url=uri,
payload=req_body,
headers=req_headers)
else:
result = urlfetch.get(url=uri,
payload=req_body,
headers=req_headers)
return result
resp = line_http('https://api.line.me/v1/profile', {},'xxxxxxxxxxx', 'get')
r = json.loads(resp.body)
pprint(r)
mid = r['mid']
req_body={'to':mid, 'messages':[{'type': 'text', 'text': "SPBotReport finished."}]}
jsonStr = json.dumps(req_body)
resp = line_http('https://api.line.me/v2/bot/message/push', jsonStr, 'xxxxxxxxxxx')
if resp.status == 200:
print("SPBotReport LINE text finished successfully.")
sys.exit()
else:
print("Status:%s, Reason:%s" % (resp.status, resp.reason))
if resp.headers["content-type"].find("json") > 0:
r = json.loads(resp.body)
print("message: %s" % r["message"])
是否使用。 VPN或系统是beh指定防火墙? –
这是一个错误,它已被修复。我遇到了同样的问题,今天没事。 –