python - http.client 在 Python 中不适用于本地主机
问题描述
我的代码:
import http.client
h1 = http.client.HTTPConnection('127.0.0.1')
h1.request('GET', '/')
我也尝试使用 localhost 而不是 IP,但它也不起作用。我确信我的 apache 正在运行,因为我在浏览器中进行了测试。
Traceback (most recent call last):
File "/home/kali/i1.py", line 4, in <module>
h1.request('GET', '/')
File "/usr/lib/python3.9/http/client.py", line 1279, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/lib/python3.9/http/client.py", line 1325, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/usr/lib/python3.9/http/client.py", line 1274, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/lib/python3.9/http/client.py", line 1034, in _send_output
self.send(msg)
File "/usr/lib/python3.9/http/client.py", line 974, in send
self.connect()
File "/usr/lib/python3.9/http/client.py", line 945, in connect
self.sock = self._create_connection(
File "/usr/lib/python3.9/socket.py", line 844, in create_connection
raise err
File "/usr/lib/python3.9/socket.py", line 832, in create_connection
sock.connect(sa)
解决方案
推荐阅读
- javascript - 正则表达式按预期工作,但在 JaVaScript 中不起作用
- java - 使用带有 ExtJWNL 的 Jfreeling 在 Java 上出现 SIGSEGV 错误
- dom - 在库的 Common Lisp 生态系统中,如何使用 Clss 和/或 Plump 而不是 Parenscript 获取 DOM 的活动元素?
- javascript - 表单输入根据选择的类别而变化
- javascript - 从 redux 选择器返回 Monad
- php - PHP - 如何删除 GCP 存储桶文件夹及其中的所有文件/文件夹?
- flutter - Flutter Grid 模态底板
- android - 在某些设备上从 Play 商店下载后,我的应用程序卡在白屏
- amazon-web-services - 使用 CRON 的特定日期的 AWS 红移计划
- jdbc - 在哪里可以获得 jooby 2.10.0 的 jooq 和 jdbc 模块?