No project description provided
Project description
CERN Requests
Enables using requests without having to configure the CERN Root certificates.
Inspired by certifi, requests-kerberos and cern-sso-python
The Root certificate bundle is copied from the linuxsoft cern page and can also be created manually by downloading the CERN Grid Certification Authority files from cafiles.cern.ch/cafiles.
Installation
Requires Python 2.7 or Python 3.4+
pip install cernrequests
Prerequisites
Request a Grid User Certificate and convert into public and private key:
mkdir -p ~/private
openssl pkcs12 -clcerts -nokeys -in myCertificate.p12 -out ~/private/usercert.pem
openssl pkcs12 -nocerts -in myCertificate.p12 -out ~/private/userkey.tmp.pem
openssl rsa -in ~/private/userkey.tmp.pem -out ~/private/userkey.pem
The certificates have to be passwordless.
Usage
Example
import cernrequests
url = "https://<your-cern-website>"
response = cernrequests.get(url)
Cookies Example
If you want to access a website which requires CERN Single Sign-on cookies you can do the following:
import cernrequests
url = "https://<your-cern-website>"
cookies = cernrequests.get_sso_cookies(url)
response = cernrequests.get(url, cookies=cookies)
Alternative usage
If you want to use requests directly without the CERN wrapper you can get the exact same functionality by doing:
import requests
from cernrequests import certs
url = "https://<your-cern-website>"
cert = certs.default_user_certificate_paths()
ca_bundle = certs.where()
response = requests.get(url, cert=cert, verify=ca_bundle)
Configuration
The default user certificate paths are first ~\private\ and ~\.globus\ for fallback. The default public key file is usercert.pem and the default private key file name is userkey.pem
You can configure the default grid user certificate path by setting the CERN_CERTIFICATE_PATH environment variable.
For example:
export CERN_CERTIFICATE_PATH=${HOME}/my_custom_folder
This will still assume that your filenames are usercert.pem and userkey.pem
Write this line in your .bashrc to make the configuration persistent.
Alternatively you can also specify the paths directly in your code:
import cernrequests
url = "https://<your-cern-website>"
cert = "my/custom/path/cert.pem" # Public key path
key = "my/custom/path/key.pem" # Private key path
cernrequests.get(url, cert=(cert,key))
This way you can even use custom names such as cert.pem and key.pem
References
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cernrequests-0.2.0.tar.gz.
File metadata
- Download URL: cernrequests-0.2.0.tar.gz
- Upload date:
- Size: 15.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8a4b6ad7baaea7a66a638475cb94bc75db1fd8ab1120b0abb7d622444c652a4a
|
|
| MD5 |
61974039f0e261d69002f7da92466ea5
|
|
| BLAKE2b-256 |
ab824ed9abac445014ca4c2c7207767fd3d0d9ca469ae487bd2bacb11956be83
|
File details
Details for the file cernrequests-0.2.0-py3-none-any.whl.
File metadata
- Download URL: cernrequests-0.2.0-py3-none-any.whl
- Upload date:
- Size: 18.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c6bf05488de64abf0c39c7479efb60f53d0fdae17c17a654571118607e92e5b6
|
|
| MD5 |
6473941ff140b2b4fc12cc35885846d0
|
|
| BLAKE2b-256 |
3b71c9e941dcf97119b0813fee905696024d2bf74cd8ddba1e28c6ce45400075
|