Last active
April 29, 2020 16:46
-
-
Save elowy01/6e841c87cf5cfe2d14fe3fbd9c4b1339 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Providing auth in Request | |
requests.get('https://api.github.com', auth=(username, pwd)) | |
## Downloading a file | |
# Excellent article on: | |
https://www.codementor.io/@aviaryan/downloading-files-from-urls-in-python-77q3bs0un | |
import requests | |
resp = requests.get("http://www.example.com", allow_redirects=True) | |
## Reading as text | |
resp.text | |
## Read as bytes | |
resp.content | |
## Response code | |
resp.status_code | |
## Accessing url of query | |
print(response.request.url) | |
########################################## | |
# Uploading a file: | |
import requests | |
username='username' | |
password='root' | |
url="http://hh.fire-test.sdo.ebi.ac.uk/fire/objects" | |
# 'test.txt' is the file to be uploaded | |
files = {'file' : open('test.txt', 'rb')} | |
# creating headers | |
header = { | |
"x-fire-path" : "test-dir/test-file", | |
"x-fire-size" : "14", | |
"x-fire-md5" : "6c9c5b1703ab5994eab0a38f96254158" | |
} | |
res=requests.post(url, auth=(username, password), files = files, headers=header) | |
print(res.status_code) | |
print(res.text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment