Skip to content

Commit 40f2009

Browse files
download file by http requests
1 parent b70d52b commit 40f2009

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Diff for: download_file.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import requests
2+
3+
4+
def download_with_auth(url, file_path, username, password):
5+
auth = (username, password)
6+
res = requests.get(url, auth=auth)
7+
write_file(res, file_path)
8+
9+
10+
def download(url, file_path):
11+
res = requests.get(url)
12+
write_file(res, file_path)
13+
14+
15+
def write_file(res, file_path):
16+
res_content = res.content
17+
file = open(file_path, "wb")
18+
file.write(res_content)
19+
print("Done result={}".format(file_path))

0 commit comments

Comments
 (0)