Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

🐛 fixed #14 Updated the content-type #23

Merged
merged 1 commit into from
Jul 27, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,15 @@ def upload_music(remoteDirectory):
# first check if the folder already exists
existCheck = requests.get(fullurl, auth=(username, password))

# configure header
headers = {'Slug': filename}

# if the file does not yet exist (everything except 200 code) then create that file
if not existCheck.status_code == 200:
# error handling, when an error occurs, it will print the error and stop the script from running
try:

# configure header, set content-type as mpeg and charset to utf-8 to make sure that filenames with special characters are not being misinterpreted
headers = {'Content-Type': 'audio/mpeg; charset=utf-8', }

# make the put request, this uploads the file
r = requests.put(fullurl, data=open(path, 'rb'), headers=headers, auth=(username, password))
print("")
print(r.text)
Expand Down