Skip to content

Commit d0dc08d

Browse files
committed
set the encoding consistently to be 'utf-8'
1 parent 8909473 commit d0dc08d

File tree

2 files changed

+3
-9
lines changed

2 files changed

+3
-9
lines changed

scrapy_zyte_api/handler.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ def __init__(
3232
self._stats = crawler.stats
3333
self._job_id = crawler.settings.get("JOB")
3434
self._session = create_session()
35-
self._encoding = "utf-8"
3635

3736
@classmethod
3837
def from_crawler(cls, crawler):
@@ -89,9 +88,7 @@ async def _download_request(
8988
if api_response.get("browserHtml"):
9089
# Using TextResponse because browserHtml always returns a browser-rendered page
9190
# even when requesting files (like images)
92-
return ZyteAPITextResponse.from_api_response(
93-
api_response, request=request, encoding=self._encoding
94-
)
91+
return ZyteAPITextResponse.from_api_response(api_response, request=request)
9592
else:
9693
return ZyteAPIResponse.from_api_response(api_response, request=request)
9794

scrapy_zyte_api/responses.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,11 @@ def _prepare_headers(init_headers: Optional[List[Dict[str, str]]]):
2323

2424
class ZyteAPITextResponse(ZyteAPIMixin, TextResponse):
2525
@classmethod
26-
def from_api_response(
27-
cls, api_response: Dict, *, request: Request = None, encoding: str = "utf-8"
28-
):
26+
def from_api_response(cls, api_response: Dict, *, request: Request = None):
2927
return cls(
3028
url=api_response["url"],
3129
status=200,
32-
body=api_response["browserHtml"].encode(encoding),
33-
encoding=encoding,
30+
body=api_response["browserHtml"].encode("utf-8"),
3431
request=request,
3532
flags=["zyte-api"],
3633
headers=cls._prepare_headers(api_response.get("httpResponseHeaders")),

0 commit comments

Comments
 (0)