streamlink: plugins.afreeca: Failed to open segment, Unable to open URL & 400 Client Error: Bad Request for url

Plugin Issue

  • This is a plugin issue and I have read the contribution guidelines.
  • I am using the latest development version from the master branch.

Description

When trying to download a live afreeca stream, after a few seconds or minutes of downloading, streamlink returns Failed to open segment xxx: Unable to open URL and 400 Client Error: Bad Request for url.

It occurs for every stream I’ve tried and was working fine a few days ago, so I presume Afreeca may have updated their site in some way very recently.

This is a similar issue to this bug report from a few months ago.

Reproduction steps / Explicit stream URLs to test

Example:

streamlink --loglevel trace --afreeca-username ******** --afreeca-password ******** https://play.afreecatv.com/joey1114/ best -o C:\output.ts

Log output

[plugins.afreeca][debug] Restored cookies: _au, PdboxBbs, PdboxSaveTicket, PdboxTicket, PdboxUser, RDB, isBbs
[cli][debug] OS:         Windows 10
[cli][debug] Python:     3.8.7
[cli][debug] Streamlink: 2.1.2
[cli][debug] Requests(2.25.1), Socks(1.7.1), Websocket(1.0.0)
[cli][debug] Arguments:
[cli][debug]  url=https://play.afreecatv.com/joey1114/233286167
[cli][debug]  stream=['best']
[cli][debug]  --loglevel=debug
[cli][debug]  --player="C:\Program Files\mpv\mpv.exe" 
[cli][debug]  --output=C:\output.ts
[cli][debug]  --default-stream=['720p', '720p60', '1080p', '1080p60', '480p', 'medium', 'best']
[cli][debug]  --rtmpdump=C:\Program Files (x86)\Streamlink\rtmpdump\rtmpdump.exe
[cli][debug]  --ffmpeg-ffmpeg=C:\Program Files (x86)\Streamlink\ffmpeg\ffmpeg.exe
[cli][debug]  --afreeca-username=********
[cli][debug]  --afreeca-password=********
[cli][info] Found matching plugin afreeca for URL https://play.afreecatv.com/joey1114/233286167
[plugins.afreeca][debug] Attempting to authenticate using cached cookies
[cli][info] Available streams: sd (worst), hd, original (best)
[cli][info] Opening stream: original (hls)
[stream.hls][debug] Reloading playlist
[stream.hls][debug] First Sequence: 3568; Last Sequence: 3573
[stream.hls][debug] Start offset: 0; Duration: None; Start Sequence: 3571; End Sequence: None
[stream.hls][debug] Adding segment 3571 to queue
[cli][debug] Pre-buffering 8192 bytes
[stream.hls][debug] Adding segment 3572 to queue
[stream.hls][debug] Adding segment 3573 to queue
[stream.hls][debug] Reloading playlist
[stream.hls][debug] Adding segment 3574 to queue
[stream.hls][debug] Reloading playlist
[stream.hls][debug] Adding segment 3575 to queue
[stream.hls][debug] Reloading playlist
[stream.hls][debug] Adding segment 3576 to queue
[stream.hls][debug] Download of segment 3571 complete
[cli][debug] Checking file output
[cli][debug] Writing stream to output
[stream.hls][debug] Reloading playlist
[stream.hls][debug] Adding segment 3577 to queue
[stream.hls][debug] Adding segment 3578 to queue
[stream.hls][debug] Reloading playlist
[stream.hls][debug] Adding segment 3579 to queue
[stream.hls][debug] Reloading playlist
[stream.hls][debug] Adding segment 3580 to queue
[stream.hls][debug] Reloading playlist
[stream.hls][debug] Adding segment 3581 to queue
[stream.hls][debug] Download of segment 3572 complete
[download][..12-59-20.88 joey1114.ts] Written 2.0 MB (10s @ 195.6 KB/s)                                                [stream.hls][debug] Reloading playlist
[stream.hls][debug] Adding segment 3582 to queue
[stream.hls][debug] Reloading playlist
[stream.hls][debug] Adding segment 3583 to queue
[stream.hls][debug] Reloading playlist
[stream.hls][debug] Adding segment 3584 to queue
[stream.hls][debug] Adding segment 3585 to queue
[stream.hls][debug] Reloading playlist
[stream.hls][debug] Adding segment 3586 to queue
[stream.hls][debug] Reloading playlist
[stream.hls][debug] Adding segment 3587 to queue
[stream.hls][debug] Reloading playlist
[stream.hls][debug] Adding segment 3588 to queue
[stream.hls][debug] Reloading playlist
[stream.hls][debug] Download of segment 3573 complete
[download][..12-59-20.88 joey1114.ts] Written 4.0 MB (24s @ 164.3 KB/s)                                                [stream.hls][debug] Adding segment 3589 to queue
[stream.hls][debug] Reloading playlist
[stream.hls][debug] Adding segment 3590 to queue
[stream.hls][error] Failed to open segment 3574: Unable to open URL: http://pc-web.stream.afreecatv.com/live-stm-09/1920x1080/233286167-common-original-hls_3573_0000009300F800E526B9157C7CE96A68.TS (400 Client Error: Bad Request for url: http://pc-web.stream.afreecatv.com/live-stm-09/1920x1080/233286167-common-original-hls_3573_0000009300F800E526B9157C7CE96A68.TS?aid=.A32.7bbT56vyHM9fKZk.qQpxQlTkXbc6sWFCoLYnErUwzm6lKrsWI3_c51O8L58MTp_9PSjeH7DkvYQDVjj_b14Lc5DPCc39ZhGrfour8LukPIMrAnoyKF7n7x5cXpxYBWErbg-x9B14z8DsHd1k)
[stream.hls][debug] Reloading playlist
[stream.hls][debug] Adding segment 3591 to queue
[stream.hls][debug] Adding segment 3592 to queue
[stream.hls][debug] Reloading playlist
[stream.hls][error] Failed to open segment 3575: Unable to open URL: http://pc-web.stream.afreecatv.com/live-stm-09/1920x1080/233286167-common-original-hls_3574_00000082001000412591A45AC5E8E586.TS (400 Client Error: Bad Request for url: http://pc-web.stream.afreecatv.com/live-stm-09/1920x1080/233286167-common-original-hls_3574_00000082001000412591A45AC5E8E586.TS?aid=.A32.7bbT56vyHM9fKZk.qQpxQlTkXbc6sWFCoLYnErUwzm6lKrsWI3_c51O8L58MTp_9PSjeH7DkvYQDVjj_b14Lc5DPCc39ZhGrfour8LukPIMrAnoyKF7n7x5cXpxYBWErbg-x9B14z8DsHd1k)
[stream.hls][debug] Adding segment 3593 to queue
[stream.hls][debug] Reloading playlist
[stream.hls][debug] Adding segment 3594 to queue
[stream.hls][error] Failed to open segment 3576: Unable to open URL: http://pc-web.stream.afreecatv.com/live-stm-09/1920x1080/233286167-common-original-hls_3575_000000F60064001B5D661905F7FD8606.TS (400 Client Error: Bad Request for url: http://pc-web.stream.afreecatv.com/live-stm-09/1920x1080/233286167-common-original-hls_3575_000000F60064001B5D661905F7FD8606.TS?aid=.A32.7bbT56vyHM9fKZk.qQpxQlTkXbc6sWFCoLYnErUwzm6lKrsWI3_c51O8L58MTp_9PSjeH7DkvYQDVjj_b14Lc5DPCc39ZhGrfour8LukPIMrAnoyKF7n7x5cXpxYBWErbg-x9B14z8DsHd1k)
[stream.hls][debug] Reloading playlist
[stream.hls][debug] Adding segment 3595 to queue
[stream.hls][error] Failed to open segment 3577: Unable to open URL: http://pc-web.stream.afreecatv.com/live-stm-09/1920x1080/233286167-common-original-hls_3576_0000007F00420078BC5541DF1A29B907.TS (400 Client Error: Bad Request for url: http://pc-web.stream.afreecatv.com/live-stm-09/1920x1080/233286167-common-original-hls_3576_0000007F00420078BC5541DF1A29B907.TS?aid=.A32.7bbT56vyHM9fKZk.qQpxQlTkXbc6sWFCoLYnErUwzm6lKrsWI3_c51O8L58MTp_9PSjeH7DkvYQDVjj_b14Lc5DPCc39ZhGrfour8LukPIMrAnoyKF7n7x5cXpxYBWErbg-x9B14z8DsHd1k)
[stream.hls][debug] Reloading playlist
[stream.hls][debug] Adding segment 3596 to queue
[stream.hls][debug] Reloading playlist
[stream.hls][debug] Adding segment 3597 to queue
[stream.hls][error] Failed to open segment 3578: Unable to open URL: http://pc-web.stream.afreecatv.com/live-stm-09/1920x1080/233286167-common-original-hls_3577_00000099008600CC662098DCFA921840.TS (400 Client Error: Bad Request for url: http://pc-web.stream.afreecatv.com/live-stm-09/1920x1080/233286167-common-original-hls_3577_00000099008600CC662098DCFA921840.TS?aid=.A32.7bbT56vyHM9fKZk.qQpxQlTkXbc6sWFCoLYnErUwzm6lKrsWI3_c51O8L58MTp_9PSjeH7DkvYQDVjj_b14Lc5DPCc39ZhGrfour8LukPIMrAnoyKF7n7x5cXpxYBWErbg-x9B14z8DsHd1k)
[stream.hls][debug] Reloading playlist
[stream.hls][debug] Adding segment 3598 to queue
[stream.hls][debug] Adding segment 3599 to queue
[stream.hls][error] Failed to open segment 3579: Unable to open URL: http://pc-web.stream.afreecatv.com/live-stm-09/1920x1080/233286167-common-original-hls_3578_00000045006F002DB0E29BB658211A6C.TS (400 Client Error: Bad Request for url: http://pc-web.stream.afreecatv.com/live-stm-09/1920x1080/233286167-common-original-hls_3578_00000045006F002DB0E29BB658211A6C.TS?aid=.A32.7bbT56vyHM9fKZk.qQpxQlTkXbc6sWFCoLYnErUwzm6lKrsWI3_c51O8L58MTp_9PSjeH7DkvYQDVjj_b14Lc5DPCc39ZhGrfour8LukPIMrAnoyKF7n7x5cXpxYBWErbg-x9B14z8DsHd1k)
[stream.hls][debug] Reloading playlist
[stream.hls][debug] Adding segment 3600 to queue
[stream.hls][debug] Reloading playlist
[stream.hls][debug] Adding segment 3601 to queue
[stream.hls][error] Failed to open segment 3580: Unable to open URL: http://pc-web.stream.afreecatv.com/live-stm-09/1920x1080/233286167-common-original-hls_3579_0000003C006C003A9A144833C975CD7C.TS (400 Client Error: Bad Request for url: http://pc-web.stream.afreecatv.com/live-stm-09/1920x1080/233286167-common-original-hls_3579_0000003C006C003A9A144833C975CD7C.TS?aid=.A32.7bbT56vyHM9fKZk.qQpxQlTkXbc6sWFCoLYnErUwzm6lKrsWI3_c51O8L58MTp_9PSjeH7DkvYQDVjj_b14Lc5DPCc39ZhGrfour8LukPIMrAnoyKF7n7x5cXpxYBWErbg-x9B14z8DsHd1k)
[stream.hls][debug] Reloading playlist
[stream.hls][debug] Adding segment 3602 to queue
[stream.hls][error] Failed to open segment 3581: Unable to open URL: http://pc-web.stream.afreecatv.com/live-stm-09/1920x1080/233286167-common-original-hls_3580_0000008F00B900804692694E680934E1.TS (400 Client Error: Bad Request for url: http://pc-web.stream.afreecatv.com/live-stm-09/1920x1080/233286167-common-original-hls_3580_0000008F00B900804692694E680934E1.TS?aid=.A32.7bbT56vyHM9fKZk.qQpxQlTkXbc6sWFCoLYnErUwzm6lKrsWI3_c51O8L58MTp_9PSjeH7DkvYQDVjj_b14Lc5DPCc39ZhGrfour8LukPIMrAnoyKF7n7x5cXpxYBWErbg-x9B14z8DsHd1k)
[stream.hls][debug] Reloading playlist
[stream.hls][debug] Adding segment 3603 to queue
[stream.hls][error] Failed to open segment 3582: Unable to open URL: http://pc-web.stream.afreecatv.com/live-stm-09/1920x1080/233286167-common-original-hls_3581_00000088006100F607CCABAD91F109F2.TS (400 Client Error: Bad Request for url: http://pc-web.stream.afreecatv.com/live-stm-09/1920x1080/233286167-common-original-hls_3581_00000088006100F607CCABAD91F109F2.TS?aid=.A32.7bbT56vyHM9fKZk.qQpxQlTkXbc6sWFCoLYnErUwzm6lKrsWI3_c51O8L58MTp_9PSjeH7DkvYQDVjj_b14Lc5DPCc39ZhGrfour8LukPIMrAnoyKF7n7x5cXpxYBWErbg-x9B14z8DsHd1k)
[stream.hls][debug] Adding segment 3604 to queue
[stream.hls][error] Failed to open segment 3583: Unable to open URL: http://pc-web.stream.afreecatv.com/live-stm-09/1920x1080/233286167-common-original-hls_3582_0000000B00A400A5B830029EEF2E4DDD.TS (400 Client Error: Bad Request for url: http://pc-web.stream.afreecatv.com/live-stm-09/1920x1080/233286167-common-original-hls_3582_0000000B00A400A5B830029EEF2E4DDD.TS?aid=.A32.7bbT56vyHM9fKZk.qQpxQlTkXbc6sWFCoLYnErUwzm6lKrsWI3_c51O8L58MTp_9PSjeH7DkvYQDVjj_b14Lc5DPCc39ZhGrfour8LukPIMrAnoyKF7n7x5cXpxYBWErbg-x9B14z8DsHd1k)
[stream.hls][debug] Reloading playlist
[stream.hls][debug] Adding segment 3605 to queue
[stream.hls][error] Failed to open segment 3584: Unable to open URL: http://pc-web.stream.afreecatv.com/live-stm-09/1920x1080/233286167-common-original-hls_3583_00000092001F007F1A573CD31057DD16.TS (400 Client Error: Bad Request for url: http://pc-web.stream.afreecatv.com/live-stm-09/1920x1080/233286167-common-original-hls_3583_00000092001F007F1A573CD31057DD16.TS?aid=.A32.7bbT56vyHM9fKZk.qQpxQlTkXbc6sWFCoLYnErUwzm6lKrsWI3_c51O8L58MTp_9PSjeH7DkvYQDVjj_b14Lc5DPCc39ZhGrfour8LukPIMrAnoyKF7n7x5cXpxYBWErbg-x9B14z8DsHd1k)
[stream.hls][debug] Adding segment 3606 to queue
[stream.hls][error] Failed to open segment 3585: Unable to open URL: http://pc-web.stream.afreecatv.com/live-stm-09/1920x1080/233286167-common-original-hls_3584_0000002F005300F97FD4D8F857EDCFBF.TS (400 Client Error: Bad Request for url: http://pc-web.stream.afreecatv.com/live-stm-09/1920x1080/233286167-common-original-hls_3584_0000002F005300F97FD4D8F857EDCFBF.TS?aid=.A32.7bbT56vyHM9fKZk.qQpxQlTkXbc6sWFCoLYnErUwzm6lKrsWI3_c51O8L58MTp_9PSjeH7DkvYQDVjj_b14Lc5DPCc39ZhGrfour8LukPIMrAnoyKF7n7x5cXpxYBWErbg-x9B14z8DsHd1k)
[stream.hls][debug] Adding segment 3607 to queue
[stream.hls][error] Failed to open segment 3586: Unable to open URL: http://pc-web.stream.afreecatv.com/live-stm-09/1920x1080/233286167-common-original-hls_3585_0000004600660013A6CAC7761E582F70.TS (400 Client Error: Bad Request for url: http://pc-web.stream.afreecatv.com/live-stm-09/1920x1080/233286167-common-original-hls_3585_0000004600660013A6CAC7761E582F70.TS?aid=.A32.7bbT56vyHM9fKZk.qQpxQlTkXbc6sWFCoLYnErUwzm6lKrsWI3_c51O8L58MTp_9PSjeH7DkvYQDVjj_b14Lc5DPCc39ZhGrfour8LukPIMrAnoyKF7n7x5cXpxYBWErbg-x9B14z8DsHd1k)
[stream.hls][debug] Reloading playlist
[stream.hls][debug] Adding segment 3608 to queue
[stream.hls][error] Failed to open segment 3587: Unable to open URL: http://pc-web.stream.afreecatv.com/live-stm-09/1920x1080/233286167-common-original-hls_3586_000000E100C00083A7811715788D5CD9.TS (400 Client Error: Bad Request for url: http://pc-web.stream.afreecatv.com/live-stm-09/1920x1080/233286167-common-original-hls_3586_000000E100C00083A7811715788D5CD9.TS?aid=.A32.7bbT56vyHM9fKZk.qQpxQlTkXbc6sWFCoLYnErUwzm6lKrsWI3_c51O8L58MTp_9PSjeH7DkvYQDVjj_b14Lc5DPCc39ZhGrfour8LukPIMrAnoyKF7n7x5cXpxYBWErbg-x9B14z8DsHd1k)
[stream.hls][debug] Adding segment 3609 to queue
[stream.hls][error] Failed to open segment 3588: Unable to open URL: http://pc-web.stream.afreecatv.com/live-stm-09/1920x1080/233286167-common-original-hls_3587_0000002A009B001FCB608D24D5AFCD13.TS (400 Client Error: Bad Request for url: http://pc-web.stream.afreecatv.com/live-stm-09/1920x1080/233286167-common-original-hls_3587_0000002A009B001FCB608D24D5AFCD13.TS?aid=.A32.7bbT56vyHM9fKZk.qQpxQlTkXbc6sWFCoLYnErUwzm6lKrsWI3_c51O8L58MTp_9PSjeH7DkvYQDVjj_b14Lc5DPCc39ZhGrfour8LukPIMrAnoyKF7n7x5cXpxYBWErbg-x9B14z8DsHd1k)
[stream.hls][debug] Adding segment 3610 to queue
[stream.hls][error] Failed to open segment 3589: Unable to open URL: http://pc-web.stream.afreecatv.com/live-stm-09/1920x1080/233286167-common-original-hls_3588_000000AF009500592DC89312BCAA693E.TS (400 Client Error: Bad Request for url: http://pc-web.stream.afreecatv.com/live-stm-09/1920x1080/233286167-common-original-hls_3588_000000AF009500592DC89312BCAA693E.TS?aid=.A32.7bbT56vyHM9fKZk.qQpxQlTkXbc6sWFCoLYnErUwzm6lKrsWI3_c51O8L58MTp_9PSjeH7DkvYQDVjj_b14Lc5DPCc39ZhGrfour8LukPIMrAnoyKF7n7x5cXpxYBWErbg-x9B14z8DsHd1k)
[stream.hls][debug] Adding segment 3611 to queue
[stream.hls][error] Failed to open segment 3590: Unable to open URL: http://pc-web.stream.afreecatv.com/live-stm-09/1920x1080/233286167-common-original-hls_3589_0000003600FC0038E4724AF8DFC3B088.TS (400 Client Error: Bad Request for url: http://pc-web.stream.afreecatv.com/live-stm-09/1920x1080/233286167-common-original-hls_3589_0000003600FC0038E4724AF8DFC3B088.TS?aid=.A32.7bbT56vyHM9fKZk.qQpxQlTkXbc6sWFCoLYnErUwzm6lKrsWI3_c51O8L58MTp_9PSjeH7DkvYQDVjj_b14Lc5DPCc39ZhGrfour8LukPIMrAnoyKF7n7x5cXpxYBWErbg-x9B14z8DsHd1k)
[stream.hls][debug] Adding segment 3612 to queue
error: Error when reading from stream: Read timeout, exiting
[stream.segmented][debug] Closing worker thread
[stream.segmented][debug] Closing writer thread
[stream.hls][error] Failed to open segment 3591: Unable to open URL: http://pc-web.stream.afreecatv.com/live-stm-09/1920x1080/233286167-common-original-hls_3590_000000270041005F482E14A10CFD97EE.TS (400 Client Error: Bad Request for url: http://pc-web.stream.afreecatv.com/live-stm-09/1920x1080/233286167-common-original-hls_3590_000000270041005F482E14A10CFD97EE.TS?aid=.A32.7bbT56vyHM9fKZk.qQpxQlTkXbc6sWFCoLYnErUwzm6lKrsWI3_c51O8L58MTp_9PSjeH7DkvYQDVjj_b14Lc5DPCc39ZhGrfour8LukPIMrAnoyKF7n7x5cXpxYBWErbg-x9B14z8DsHd1k)
[cli][info] Stream ended
[cli][info] Closing currently open stream...

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Comments: 18 (6 by maintainers)

Most upvoted comments

In my case ffmpeg will produce laggy video files ( timeline uneven ) when the network is slow.

https://github.com/streamlink/streamlink/blob/8ef3c73480f172f1535d549a1a6c85c7da1c0c1f/src/streamlink/plugin/api/http_session.py#L173-L183

You need to reset the retries counter once a new segment is requested without any error.

Helpful to increase the total_retries number and shorten the delay interval. I also write extra wait-retry logic outside of the streamlink command.

As for hls.py, dont catch any Exception:

    def fetch(self, sequence: Sequence) -> Optional[Response]:
        return ...

# and shorten playlist_reload_time

(3 days ago 2.4.0 started giving me IncompleteRead(696320 bytes read, 1411724 more expected errors, after months of bug-free, heavy use. So today I updated to 3.2.0.)

I then was getting these “Failed to fetch segment xyz: Unable to open URL” errors, for high-quality afreeca.tv streams. –hls-segment-threads 10 appears to have solved the issue for me.

Without it, stream downloads would work fine for the first 15-75 seconds, at which point 95% of segments start to fail. This occurs with regular full-cam streams (e.g. 1920x1080 6000kbps), but does not occur for low-quality streams (e.g. 576x1024 2500kbps, 576x1024 2000kbps). I also tested with my usual network-caching and file-caching = 5000 settings, and up to 50000, but it didn’t help.

Example basic command that resulted in Unable to open URL errors and missing segments in the resulting file: streamlink play.afreecatv.com/channelname best --output test{time}.ts Example basic command that resulted in no errors and no missing segments: streamlink --hls-segment-threads 10 play.afreecatv.com/channelname best --output test{time}.ts

@gravyboat Yes, because this could potentially be worked around by enforcing a higher number of segment retries if it’s indeed a server segment response issue and not related to a session token expiring, etc. But that’s just a first thought. I don’t have the time or motivation to investigate this myself. I’ve reopened this thread, so that there are no further duplicates. If this can’t be worked around, we can close it again.