Skip to content

Instantly share code, notes, and snippets.

@KD-MM2
Last active April 8, 2023 20:03
Show Gist options
  • Save KD-MM2/f3128fdf52062930020b6cb05a8d176f to your computer and use it in GitHub Desktop.
Save KD-MM2/f3128fdf52062930020b6cb05a8d176f to your computer and use it in GitHub Desktop.
github ssl verify request get python
import requests
import base64
# replace with your personal access token(classic)
github_pat = "ghp_abcdfeghi......"
# encode pat using base64
encoded = base64.base64encode(github_pat.encode())
# check the encoded base64
print(encoded)
# decode the encoded pat
ghp = base64.b64decode(github_pat).decode()
# check the decoded
print(ghp)
# Set the URL for the file you want to access
url = "https://raw.githubusercontent.com/<username>/<reponame>/<branchname>/<filename or folder/filename>"
# Make a GET request to the file URL with SSL verification
response = requests.get(url.decode(), headers={"Authorization": f"Bearer {ghp.decode()}"}, verify='./certs/consolidate.pem')
# to get the cert, open github.com in Safari, open github and navigate to your private repo.
# click on the lock icon on the next left of the address bar, click on Show certificate
# then select the Root CA, drag it to somewhere, then open terminal:
# `openssl x509 -in server.cer -inform DER -outform PEM >> consolidate.pem`
# now you got the cert for verify
# Print the content of the file
print(response.content.decode())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment