gpt4 book ai didi

python - 通过 python 发布时遇到问题

转载 作者:可可西里 更新时间:2023-11-01 16:06:37 29 4
gpt4 key购买 nike

我遇到了一些麻烦。我正在尝试发送 POST 并尝试按照文档进行操作,但我似乎无法做到正确。

在 github 上:https://github.com/trtmn/Python

欢迎请求请求!

# Getting documentation from :
#https://docs.python.org/2/howto/urllib2.html
import urllib
import urllib2

url = 'https://hooks.slack.com/services/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'
values = {"username": "webhookbot", "text": "This is posted to #general and comes from a bot named webhookbot.", "icon_emoji": ":ghost:"}

data = urllib.urlencode(values)
req = urllib2.Request(url, data)
response = urllib2.urlopen(req)
the_page = response.read()

最佳答案

看起来我需要将其字符串化为 JSON(我知道,但不知道如何操作)。感谢 Tim G. 的协助。

下面是功能代码:

import urllib2
import json

url = 'https://hooks.slack.com/services/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'
values = {"username": "webhookbot", "text": "This is posted to #general and comes from a bot named webhookbot.", "icon_emoji": ":ghost:"}

data = json.dumps(values)
req = urllib2.Request(url, data)
response = urllib2.urlopen(req)
the_page = response.read()

关于python - 通过 python 发布时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26751896/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com