我尝试使用Webhooks将 POST 请求发送到我的闲暇频道,但无济于事。
无论我做什么,它总是返回一个不好的请求。
是否可以在不使用Webhook的情况下发送 POST 请求到松弛状态?
编辑:我正在使用的代码
import json
import urllib.request
#import botocore.requests as requests
def lambda_handler(event, context):
webhook=event['webhook']
#response = urllib.request.urlopen(message)
#print(response)
slack_URL = 'https://hooks.slack.com/services/mywebhookurl'
# req = urllib.request.Request(SLACK_URL, json.dumps(webhook).encode('utf-8'))
json=webhook
json=json.encode('utf-8')
headers={'Content-Type': 'application/json'}
#urllib.request.add_data(data)
req = urllib.request.Request(slack_URL, json, headers)
response = urllib.request.urlopen(req)
答案 0 :(得分:1)
我认为在(df.Header1.value_counts()
.rename('Count') # Series name becomes column label for counts
.rename_axis('Values') # Index name becomes column label for unique values.
.reset_index() # Series -> DataFrame
)
# Values Count
#0 Value_1 3
#1 Value_2 2
#2 Value_3 2
中编码JSON时会出现问题。尝试以下脚本。
utf-8
如果您想使用import json
import requests
# Generate your webhook url at https://my.slack.com/services/new/incoming-webhook/
webhook_url = "https://hooks.slack.com/services/YYYYYYYYY/XXXXXXXXXXX"
slack_data = {'text': "Hi Sarath Kaul"}
response = requests.post(webhook_url, data=json.dumps(slack_data),headers={'Content-Type': 'application/json'})
print response.status_code
urllib