我编写了以下python脚本:
import httplib
conn = httplib.HTTPConnection("127.0.0.1:8080")
conn.request("HEAD", "/")
check = conn.getresponse()
print check.status, check.reason
if check.status == 200:
exit(0)
else:
exit(1)
从我的机器上运行时,我得到了正确的回复:
# python pytest.py
200 OK
但是当Travis-CI在构建时运行脚本时,会抛出以下错误:
$ python pytest.py
Traceback (most recent call last):
File "pytest.py", line 4, in <module>
check = conn.getresponse()
File "/opt/python/2.7.12/lib/python2.7/httplib.py", line 1136, in getresponse
response.begin()
File "/opt/python/2.7.12/lib/python2.7/httplib.py", line 453, in begin
version, status, reason = self._read_status()
File "/opt/python/2.7.12/lib/python2.7/httplib.py", line 409, in _read_status
line = self.fp.readline(_MAXLINE + 1)
File "/opt/python/2.7.12/lib/python2.7/socket.py", line 480, in readline
data = self._sock.recv(self._rbufsize)
socket.error: [Errno 104] Connection reset by peer
The command "python pytest.py" exited with 1.
编辑#1:
这是一个构建日志: https://travis-ci.org/geek-kb/tikal_assignment/builds/182633824
失败的原因是什么?
答案 0 :(得分:1)
看起来您正在Docker容器内的端口8080上运行服务:
Step 11 : CMD python manage.py runserver 0.0.0.0:8080
它会被暴露给主持人:
$ docker run -d -p 8080:8080 -t camelel/django
尝试从脚本连接到该端口,例如:
conn = httplib.HTTPConnection("127.0.0.1:8080")