Chinaunix

标题: python 程序报错,请教 [打印本页]

作者: yumany    时间: 2013-03-22 01:15
标题: python 程序报错,请教
本帖最后由 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
作者: jeppeter    时间: 2013-03-22 07:33
回复 1# yumany


    这个是你的服务端出了问题。
    你要检查一下你的服务端。
作者: bikong0411    时间: 2013-03-22 09:00
urllib.error.URLError: <urlopen error [Errno 104] Connection reset by peer>
这就是主要原因
作者: yumany    时间: 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())



作者: jeppeter    时间: 2013-03-22 11:12
回复 4# yumany


    最简单,你用WEB BROWSER连上你所的URL,看是什么结果,这个就明白了。
作者: yumany    时间: 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())
作者: yumany    时间: 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)






欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2