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 intall cernrequests
Prerequisites
Request a Grid User Certificate and convert into public and private key:
mkdir -p ~/.globus
openssl pkcs12 -clcerts -nokeys -in myCertificate.p12 -out ~/.globus/usercert.pem
openssl pkcs12 -nocerts -in myCertificate.p12 -out ~/.globus/userkey.tmp.pem
openssl rsa -in ~/.globus/userkey.tmp.pem -out ~/.globus/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 ~\.globus\usercert.pem
and ~\.globus\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
Hashes for cernrequests-0.1.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4a8b3e882d58200bac5d3af863bac6dca29d5e182173ee6229c71ba2ea61ebda |
|
MD5 | e48693233d6ebf4e12b7fa142d672001 |
|
BLAKE2b-256 | 02b6027cc93ad416b406e66222ec345b5e32b0c9cce6a1593263dd579763a114 |