Python 3.x Travis构建在使用带有urllib.requests.urlopen的PyOpenSSL时失败

Python 3.x Travis构建在使用带有urllib.requests.urlopen的PyOpenSSL时失败,python-3.x,ssl,python-requests,travis-ci,urllib3,Python 3.x,Ssl,Python Requests,Travis Ci,Urllib3,因此,最近我的构建系统开始出现故障,之前的工作构建和新构建之间唯一的差异是“行为准则”标记文件,它通常不会影响代码 我的测试系统是基于TravisCI构建的,我收到的当前错误是: Traceback (most recent call last): File "/home/travis/conda/envs/tenv/lib/python3.6/site-packages/nose/case.py", line 198, in runTest self.test(*self.arg)

因此,最近我的构建系统开始出现故障,之前的工作构建和新构建之间唯一的差异是“行为准则”标记文件,它通常不会影响代码

我的测试系统是基于TravisCI构建的,我收到的当前错误是:

Traceback (most recent call last):
  File "/home/travis/conda/envs/tenv/lib/python3.6/site-packages/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/home/travis/build/Sulstice/cocktail-shaker/tests/test_file_handler.py", line 47, in test_file_production
    FileWriter("tests/test", modified_molecules, "cdxml")
  File "/home/travis/build/Sulstice/cocktail-shaker/cocktail_shaker/file_handler.py", line 60, in __init__
    method_to_call(self)
  File "/home/travis/build/Sulstice/cocktail-shaker/cocktail_shaker/file_handler.py", line 129, in cactus_writer
    response = request.get()
  File "/home/travis/build/Sulstice/cocktail-shaker/cocktail_shaker/request_handler.py", line 51, in get
    request = urlopen(self.url)
  File "/home/travis/conda/envs/tenv/lib/python3.6/urllib/request.py", line 223, in urlopen
    return opener.open(url, data, timeout)
  File "/home/travis/conda/envs/tenv/lib/python3.6/urllib/request.py", line 526, in open
    response = self._open(req, data)
  File "/home/travis/conda/envs/tenv/lib/python3.6/urllib/request.py", line 544, in _open
    '_open', req)
  File "/home/travis/conda/envs/tenv/lib/python3.6/urllib/request.py", line 504, in _call_chain
    result = func(*args)
  File "/home/travis/conda/envs/tenv/lib/python3.6/urllib/request.py", line 1361, in https_open
    context=self._context, check_hostname=self._check_hostname)
  File "/home/travis/conda/envs/tenv/lib/python3.6/urllib/request.py", line 1320, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [Errno 99] Cannot assign requested address>
所以我决定在局部和较低的位置进行测试,结果我收到了确切的错误。最终我得到了一个握手例外条款,这让我觉得这是TLS的问题。所以我安装了PyOpenSSL,并且它(在本地)都工作了

我想我可以将pyopenssl添加到requirements.txt中,然后再次运行我的travis构建,但是我又回到了同样的错误。所以现在我被难住了

这是我的.travis文件:

language: python
python:
  - "3.6"

# switch to new infrastructure
sudo: false

before_install:
# download and install miniconda
- wget http://repo.continuum.io/miniconda/Miniconda3-4.1.11-Linux-x86_64.sh -O miniconda.sh;
- bash miniconda.sh -b -p $HOME/conda
- export PATH="$HOME/conda/bin:$PATH"
- hash -r
- conda config --set always_yes yes --set changeps1 no
- conda update -q conda
# Useful for debugging any issues with conda
- conda info -a

# create and activate the build/test environment
- conda create -q -n tenv python=$TRAVIS_PYTHON_VERSION pip cmake
- source activate tenv

# additional .debs we need:
addons:
  apt:
    packages:
    - build-essential
    - openjdk-8-jdk
    - swig
    - libjpeg-dev

install:

# install the most recent rdkit package from the RDKit anaconda channel.
- conda install -q -c rdkit rdkit

- python setup.py install
- pip install python-coveralls
- pip install coveralls
- pip install coverage       # Add me to install coverage.py
- pip install nose           # Add me to install nose

before_script:
# RDKit
- export RDBASE=$CONDA_PREFIX/Library/share/RDKit
- echo $RDBASE

script:
- python -m nose --verbose --with-coverage

after_success:
- python -m coveralls
下面是一个请求示例:

url = https://cactus.nci.nih.gov/chemical/structure/tautomers%3ANC%28Br%29C%28%3DO%29NCC%28%3DO%29O/file/xml/\?format\=mol2\&get3d\=True

   from urllib.request import urlopen

   try:
      request = urlopen(url)
   except Exception as e:
      print (e)

您请求的网站似乎不快速或不可靠。我建议使用urllib3而不是
urllib
来配置重试。但最好的选择是避免向Travis请求外部网站,这是获得不可靠测试的最佳方法。(还有,当您不使用这些库时,为什么要用
python请求
urllib3
标记您的问题?@QuentinPradet我可以删除这段代码,并对其进行标记,以查看是否有其他途径使用该库,如果有人知道这些知识,可能会产生更稳定的测试。)。
url = https://cactus.nci.nih.gov/chemical/structure/tautomers%3ANC%28Br%29C%28%3DO%29NCC%28%3DO%29O/file/xml/\?format\=mol2\&get3d\=True

   from urllib.request import urlopen

   try:
      request = urlopen(url)
   except Exception as e:
      print (e)