免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3159 | 回复: 3
打印 上一主题 下一主题

python 程序报错,请教 [复制链接]

招聘 : IT系统运维工
论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-03-22 01:15 |显示全部楼层 |倒序浏览
本帖最后由 yumany 于 2013-03-22 01:16 编辑

大家帮忙看看,下面的错误是怎么回事呢?
Python 3.1.1
Traceback (most recent call last):
  File "/opt/python/linux64/ix86/python_3.1.1/lib/python3.1/urllib/request.py", line 1054, in do_open
    h.request(req.get_method(), req.selector, req.data, headers)
  File "/opt/python/linux64/ix86/python_3.1.1/lib/python3.1/http/client.py", line 918, in request
    self._send_request(method, url, body, headers)
  File "/opt/python/linux64/ix86/python_3.1.1/lib/python3.1/http/client.py", line 956, in _send_request
    self.endheaders(body)
  File "/opt/python/linux64/ix86/python_3.1.1/lib/python3.1/http/client.py", line 914, in endheaders
    self._send_output(message_body)
  File "/opt/python/linux64/ix86/python_3.1.1/lib/python3.1/http/client.py", line 768, in _send_output
    self.send(msg)
  File "/opt/python/linux64/ix86/python_3.1.1/lib/python3.1/http/client.py", line 716, in send
    self.connect()
  File "/opt/python/linux64/ix86/python_3.1.1/lib/python3.1/http/client.py", line 1041, in connect
    self.sock = ssl.wrap_socket(sock, self.key_file, self.cert_file)
  File "/opt/python/linux64/ix86/python_3.1.1/lib/python3.1/ssl.py", line 381, in wrap_socket
    suppress_ragged_eofs=suppress_ragged_eofs)
  File "/opt/python/linux64/ix86/python_3.1.1/lib/python3.1/ssl.py", line 135, in __init__
    raise x
  File "/opt/python/linux64/ix86/python_3.1.1/lib/python3.1/ssl.py", line 131, in __init__
    self.do_handshake()
  File "/opt/python/linux64/ix86/python_3.1.1/lib/python3.1/ssl.py", line 327, in do_handshake
    self._sslobj.do_handshake()
socket.error: [Errno 104] Connection reset by peer

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./count.py", line 246, in <module>
    stats = get_stats(product, current_FB_entry)
  File "./count.py", line 128, in get_stats
    build_info = get_api_result(build['url'])
  File "./count.py", line 54, in get_api_result
    return eval(urllib.request.urlopen(url + 'api/python').read())
  File "/opt/python/linux64/ix86/python_3.1.1/lib/python3.1/urllib/request.py", line 119, in urlopen
    return _opener.open(url, data, timeout)
  File "/opt/python/linux64/ix86/python_3.1.1/lib/python3.1/urllib/request.py", line 347, in open
    response = self._open(req, data)
  File "/opt/python/linux64/ix86/python_3.1.1/lib/python3.1/urllib/request.py", line 365, in _open
    '_open', req)
  File "/opt/python/linux64/ix86/python_3.1.1/lib/python3.1/urllib/request.py", line 325, in _call_chain
    result = func(*args)
  File "/opt/python/linux64/ix86/python_3.1.1/lib/python3.1/urllib/request.py", line 1080, in https_open
    return self.do_open(http.client.HTTPSConnection, req)
  File "/opt/python/linux64/ix86/python_3.1.1/lib/python3.1/urllib/request.py", line 1057, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [Errno 104] Connection reset by peer>
Build step 'Execute shell' marked build as failure

招聘 : IT系统运维工
论坛徽章:
0
2 [报告]
发表于 2013-03-22 09:13 |显示全部楼层
谢谢两位,下面是我的源代码,我们现在是想urllib.request.urlopen去得到jenkins指定的页面内容,我也知道主要问题出在urllib.error.URLError: <urlopen error [Errno 104] Connection reset by peer>,服务器端大概会是什么问题呢?google很多没有找出有用的信息。

jenkins = 'http://belinb.china****.net:8080/'

import chameleon
import os
import urllib.request
import sys
import datetime
import subprocess
os.system('python -V')
print 'url'
def get_api_result(url):
    """Gets the dictionary returned by Jenkins' Pyfthon API.

    @type url: str
    @param utl: URL of the job/build.

    @rtype: dict
    @return: Contains information from Jenkins Python API for the requested build/job.

    """
    return eval(urllib.request.urlopen(url + 'api/python').read())


招聘 : IT系统运维工
论坛徽章:
0
3 [报告]
发表于 2013-03-23 21:11 |显示全部楼层
本帖最后由 yumany 于 2013-03-23 21:11 编辑

现在有个问题是url这个值是在哪里定义,在脚本里没有单独定义这个变量,因为是别人写的,
如果单独在浏览器里 http://belinb.china****.net:8080/api/python,可以下载到网站内容。

def get_api_result(url):
    """Gets the dictionary returned by Jenkins' Pyfthon API.

    @type url: str
    @param utl: URL of the job/build.

    @rtype: dict
    @return: Contains information from Jenkins Python API for the requested build/job.

    """
    return eval(urllib.request.urlopen(url + 'api/python').read())

招聘 : IT系统运维工
论坛徽章:
0
4 [报告]
发表于 2013-03-23 21:32 |显示全部楼层
我试了一下简单的这样的脚本是没有问题
#!/usr/bin/env python3
import urllib.request
with urllib.request.urlopen('http://belinb.china****.net:8080/') as f:
      content = f.read()
print(content)

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP