Search helpers: Add POST support to retrieve_url

This allows passing request_data to retrieve_url in order to create a post request.

PR #21184.

---------

Co-authored-by: Chocobo1 <Chocobo1@users.noreply.github.com>
This commit is contained in:
ducalex 2024-08-17 01:32:57 -04:00 committed by GitHub
commit efdc4af448
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,4 +1,4 @@
#VERSION: 1.48
#VERSION: 1.49
# Author:
# Christophe DUMEZ (chris@qbittorrent.org)
@ -89,10 +89,10 @@ def htmlentitydecode(s: str) -> str:
return re.sub(r'&#x(\w+);', lambda x: chr(int(x.group(1), 16)), t)
def retrieve_url(url: str, custom_headers: Mapping[str, Any] = {}) -> str:
def retrieve_url(url: str, custom_headers: Mapping[str, Any] = {}, request_data: Optional[Any] = None) -> str:
""" Return the content of the url page as a string """
request = urllib.request.Request(url, headers={**headers, **custom_headers})
request = urllib.request.Request(url, request_data, {**headers, **custom_headers})
try:
response = urllib.request.urlopen(request)
except urllib.error.URLError as errno: