首页 > 解决方案 > 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 上。*该请求非常完美:

  1. 浏览器
  2. 邮差*

但是当我用我的 python 应用程序击中它时。繁荣!地址问题。

:') requests 模块也可以工作,但我只需要使用套接字即可。

socket.gaierror: [Errno 11001] getaddrinfo failed

帮助

标签: python-3.xsocketsherokunetworking

解决方案


推荐阅读