Page MenuHomePhabricator

SSLError on requesting data from Wikidata
Closed, InvalidPublic

Description

When trying to get() an item from wikidata I get the following SSL related error:

ERROR: Traceback (most recent call last):

File "/usr/local/lib/python2.7/dist-packages/pywikibot-2.0b1-py2.7.egg/pywikibot/data/api.py", line 452, in submit
  headers=headers, body=body)
File "/usr/local/lib/python2.7/dist-packages/pywikibot-2.0b1-py2.7.egg/pywikibot/tools.py", line 367, in wrapper
  return method(*__args, **__kw)
File "/usr/local/lib/python2.7/dist-packages/pywikibot-2.0b1-py2.7.egg/pywikibot/comms/http.py", line 258, in request
  raise request.data

SSLError: [Errno 185090050] _ssl.c:344: error:0B084002:x509 certificate routines:X509_load_cert_crl_file:system lib

To reproduce:
import pywikibot
repo = pywikibot.Site().data_repository()
item = pywikibot.ItemPage(repo, 'Q4115189')
item.get()


Version: core-(2.0)
Severity: normal

Details

Reference
bz71497

Event Timeline

bzimport raised the priority of this task from to Needs Triage.Nov 22 2014, 3:52 AM
bzimport set Reference to bz71497.
bzimport added a subscriber: Unknown Object (????).

Work for me with:

pywikibot.version.getversion()

u'[ssh] pywikibot-core.git (a5744db, g4204, 2014/10/04, 18:56:45, OUTDATED)'

Does this happen also when calling pywikibot.version.getversion()?

Apparently this is what you get if your certificates file is missing. What version of httplib2 do you have installed, and was it installed by a package manager or with pip?

In the latter case, please pip install --upgrade httplib2; in the former case, a bug report for your distribution might be in order.

@Fabian: SSL issue doesn't happen when I call pywikibot.version.getversion()

@Merlijn: Running "pip install --upgrade httplib2" didn't help (and on searching I find cacert.pem in the requests directory).

Completely reinstalled pywikibot (to try and remove any issues related to the egg installer but still the same issue.

u'[ssh] pywikibot-core.git (df93880, g4208, 2014/10/05, 23:53:47, n/a)'

Reading a bit at https://bugs.launchpad.net/ubuntu/+source/python-pip/+bug/1306991 it seems as though requests is broken for Ubuntu 14.04.

@Merlijn: running httplib2 version 0.9

Note that we use *httplib2*, not requests! Please try the following

$ python
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.

import httplib2
httplib2.CA_CERTS

This gives me '/etc/ssl/certs/ca-certificates.crt' for my Ubuntu 14.04-packaged httplib2, and '/path/to/venv/lib/python2.6/site-packages/httplib2-0.8_pywikibot1-py2.6.egg/httplib2/cacerts.txt' for a virtualenv.

What do you get, and does that file exist?

Sorry about that. Me getting confused between httplib and requests.

httplib2.CA_CERTS gives me /usr/local/lib/python2.7/dist-packages/httplib2-0.9-py2.7.egg/httplib2/cacerts.txt


I finally got things to work by deleting the httplib2 directory in the externals folder of pywikibot.

Is the httplib2 in core/externals necessary?

Yes. It's used by people using pywikibot-as-a-portable-package via pwb.py. I'm not sure why your system decided to a) use that directory (instead of using the system-installed one) or b) why it couldn't find it's cacerts file (which is included in the externals/httplib2 directory).

An update on this. In Amsterdam we found at that it seems as though my installation (ubuntu or python) made the cert file not readable by the process running pywikibot. Strange and weird but unlikely to be related to pywikibot itself.

valhallasw changed the task status from Declined to Invalid.Nov 27 2014, 6:31 PM
valhallasw claimed this task.

The upstream issue is https://github.com/jcgregorio/httplib2/issues/252

tl;dr: the permissions in the .tar.gz on pypi are wrong, and these permissions are restored when pip installing as root.

Workarounds:

  • fix the permissions manually
  • install pywikibot into a virtualenv
  • remove the pip installed httplib2 and replace by the distribution one
  • use pwb.py

and maybe

  • install the bundled httplib2 in externals/

also works.