python-plexapi icon indicating copy to clipboard operation
python-plexapi copied to clipboard

BadRequest: (403) forbidden when uploading subtitle

Open naveensingh opened this issue 4 years ago • 2 comments

Describe the Bug

So I'm trying to upload subtitles for an existing TV show episode using the episodes uploadSubtitles method but it's throwing the BadRequest error

Code Snippets

episode_key = '/library/metadata/608'
episode = plex.fetchItem(episode_key)
subtitles = episode.subtitleStreams()
for sub in subtitles: 
    print(f'* {sub.extendedDisplayTitle}, Key: {sub.key}, Transient: {sub.transient}, Default: {sub.default}, Selected: {sub.selected}')

mysub = "What.If.2021.S01E01.1080p.HEVC.x265-MeGusta.en.srt"
episode.uploadSubtitles(mysub)

Error (truncated for brevity):

/venv/lib/python3.9/site-packages/plexapi/server.py in query(self, key, method, headers, timeout, **kwargs)
    667                 raise NotFound(message)
    668             else:
--> 669                 raise BadRequest(message)
    670         data = response.text.encode('utf8')
    671         return ElementTree.fromstring(data) if data.strip() else None

BadRequest: (403) forbidden; https://184-105-148-83.9879f7ca51894283be3f3cb0dfdaf05a.plex.direct:8443/library/metadata/608/subtitles?title=What.If.2021.S01E01.1080p.HEVC.x265-MeGusta.en.srt&format=srt <html><head><title>Forbidden</title></head><body><h1>403 Forbidden</h1></body></html>

Expected Behavior

The subtitle should get uploaded without throwing BadRequest.

Additional Context

Similar errors were raised when trying to use removeSubtitles. setDefaultSubtitleStream worked without any problems.

Operating System and Version

Fedora 34

Plex Media Server Version

1.22.3.4523

Python Version

3.9

PlexAPI Version

4.7.2

naveensingh avatar Oct 16 '21 11:10 naveensingh

Where does mysub = "What.If.2021.S01E01.1080p.HEVC.x265-MeGusta.en.srt" exist? You need to provide the path to the file.

https://github.com/pkkid/python-plexapi/blob/d036c404efe1f218188fea1a03150ba17063164c/plexapi/video.py#L119-L129

blacktwin avatar Nov 16 '21 12:11 blacktwin

The SRT file is in the root directory of the project. That is, It's in /home/USER/project/

I'm running my script in the same directory.

Using absolute path also has the same results

naveensingh avatar Nov 16 '21 18:11 naveensingh