小编Tho*_*s M的帖子

Python 请求 [Errno 111] 在服务器上运行时连接被拒绝,但不在本地 PC 上运行

我有一个网络抓取脚本,它在我的(Windows)PC 上运行良好,但我试图让它从(Linux)网络服务器上运行。我有许多其他脚本在服务器上运行良好(连接到与此不同的网站),但是当我运行此脚本时,出现[Errno 111] Connection refused错误。

这是演示问题的脚本的最小版本:

import time
import requests
import urllib.request
from bs4 import BeautifulSoup

s = requests.Session()

target = "http://taxsearch.co.grayson.tx.us:8443/"
headers = {"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
           "Accept-Encoding": "gzip, deflate",
           "Accept-Language": "en",
           "Cache-Control": "no-cache",
           "Connection": "keep-alive",
           "Host": "taxsearch.co.grayson.tx.us:8443",
           "Pragma": "no-cache",
           "Upgrade-Insecure-Requests": "1",
           "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36"
}


time.sleep(1)
response = s.get(target, headers=headers)

if response.status_code == requests.codes.ok:
    results = BeautifulSoup(response.text, 'html.parser')

    # Do something with output
else:
    response.raise_for_status()
Run Code Online (Sandbox Code Playgroud)

这在我的 PC 上运行良好,但在服务器上运行时,出现以下错误: …

python urllib3 python-requests

6
推荐指数
0
解决办法
8331
查看次数

标签 统计

python ×1

python-requests ×1

urllib3 ×1