Thanks to visit codestin.com
Credit goes to github.com

Skip to content

stream.http: fix custom method argument#4171

Merged
gravyboat merged 1 commit into
streamlink:masterfrom
bastimeyer:stream/http/fix-args
Nov 13, 2021
Merged

stream.http: fix custom method argument#4171
gravyboat merged 1 commit into
streamlink:masterfrom
bastimeyer:stream/http/fix-args

Conversation

@bastimeyer

Copy link
Copy Markdown
Member

As mentioned in #4169, the method parameter was not working.

I've also changed valid_args() and hardcoded the supported args, because requests.Request() and requests.Session.request() don't share the same set of args and some args should not be set by the user anyway.

No tests, because there are no HTTPStream tests, and I don't want to add new ones. You can check the output of --json instead.

@bastimeyer

Copy link
Copy Markdown
Member Author

master

$ streamlink --json 'httpstream://localhost:8080 method=POST'
Traceback (most recent call last):
  File "/home/basti/venv/streamlink-39/bin/streamlink", line 33, in <module>
    sys.exit(load_entry_point('streamlink', 'console_scripts', 'streamlink')())
  File "/home/basti/repos/streamlink/src/streamlink_cli/main.py", line 1051, in main
    handle_url()
  File "/home/basti/repos/streamlink/src/streamlink_cli/main.py", line 595, in handle_url
    console.msg_json(
  File "/home/basti/repos/streamlink/src/streamlink_cli/console.py", line 79, in msg_json
    msg = dumps(out, cls=JSONEncoder, indent=2)
  File "/usr/lib/python3.9/json/__init__.py", line 234, in dumps
    return cls(
  File "/usr/lib/python3.9/json/encoder.py", line 201, in encode
    chunks = list(chunks)
  File "/usr/lib/python3.9/json/encoder.py", line 431, in _iterencode
    yield from _iterencode_dict(o, _current_indent_level)
  File "/usr/lib/python3.9/json/encoder.py", line 405, in _iterencode_dict
    yield from chunks
  File "/usr/lib/python3.9/json/encoder.py", line 405, in _iterencode_dict
    yield from chunks
  File "/usr/lib/python3.9/json/encoder.py", line 438, in _iterencode
    o = _default(o)
  File "/home/basti/repos/streamlink/src/streamlink_cli/utils/__init__.py", line 21, in default
    return obj.__json__()
  File "/home/basti/repos/streamlink/src/streamlink/stream/http.py", line 47, in __json__
    req = requests.Request(method=method, **valid_args(self.args))
TypeError: requests.models.Request() got multiple values for keyword argument 'method'

f201960

$ streamlink --json 'httpstream://localhost:8080 method=POST'
{
  "plugin": "http",
  "metadata": {
    "author": null,
    "category": null,
    "title": null
  },
  "streams": {
    "live": {
      "type": "http",
      "url": "https://localhost:8080/",
      "method": "POST",
      "headers": {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:94.0) Gecko/20100101 Firefox/94.0",
        "Accept-Encoding": "gzip, deflate",
        "Accept": "*/*",
        "Connection": "keep-alive",
        "Content-Length": "0"
      },
      "body": null
    },
    "worst": {
      "type": "http",
      "url": "https://localhost:8080/",
      "method": "POST",
      "headers": {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:94.0) Gecko/20100101 Firefox/94.0",
        "Accept-Encoding": "gzip, deflate",
        "Accept": "*/*",
        "Connection": "keep-alive",
        "Content-Length": "0"
      },
      "body": null
    },
    "best": {
      "type": "http",
      "url": "https://localhost:8080/",
      "method": "POST",
      "headers": {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:94.0) Gecko/20100101 Firefox/94.0",
        "Accept-Encoding": "gzip, deflate",
        "Accept": "*/*",
        "Connection": "keep-alive",
        "Content-Length": "0"
      },
      "body": null
    }
  }
}

@gravyboat gravyboat merged commit 0cc2046 into streamlink:master Nov 13, 2021
@bastimeyer bastimeyer deleted the stream/http/fix-args branch November 13, 2021 19:56
Billy2011 added a commit to Billy2011/streamlink-27 that referenced this pull request Nov 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants