python-3.x - socket.gaierror: [Errno 11001] getaddrinfo 在 Heroku 部署的应用程序上失败
问题描述
好的,我有一个 nodejs 服务器,它可以像这样捕获 post 请求:
app.post('/', (req, res) => {
console.log('Post request received');
console.log(req.body);
res.send("OK");
});
我有一个可以发布请求的 python 文件:
import socket
import sys
def sendPost(input):
host = "localhost"
port = 9000
data = "input="+str(input)
header = ( """POST / HTTP/1.1
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:46.0) Gecko/20100101 Firefox/46.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: close
Content-Type: application/x-www-form-urlencoded
""" )
contentLength = "Content-Length: " + str( len( data ) ) + "\n\n"
request = header + contentLength + data
return request
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(('localhost', 3000))
sock.sendall(bytes(sendPost(28), 'utf-8'))
print("Post request send")
在本地主机和我的本地机器上一切正常。
现在我想主持这个,以便我的朋友也可以发出帖子请求,这实际上是一个任务。
现在我将它托管在 heroku 上并获得了一些名称:xyz-heroku.com
现在我正在执行相同的发布请求,但在此 url 和端口 80 上。*该请求非常完美:
- 浏览器
- 邮差*
但是当我用我的 python 应用程序击中它时。繁荣!地址问题。
:') requests 模块也可以工作,但我只需要使用套接字即可。
socket.gaierror: [Errno 11001] getaddrinfo failed
帮助
解决方案
推荐阅读
- python - 如何在 S3 上的每个文件夹中抓取下载链接
- typescript - 打字稿在界面上使用省略
- python - 根据来自 2nd DataFrame 的条件,从 1 DataFrame 中选择一个值,并将该值粘贴到第一个 DataFrame 中的新列
- c# - 检查消息插入到 Azure 队列的状态
- c# - 使用 Linq 方法语法的左连接
- .net - 将服务器从 2012 升级到 2019 后,Web Socket 不适用于实际设备
- java - springboot 微服务中的专用身份验证服务
- typescript - 构建一个类型安全的装饰器
- css - 如何删除网格内列表之后的间隙?
- hyperlink - 如何使用剑道面板栏打开一个新的链接标签