LocalProtocolError: Too little data for declared Content-Length #3041
-
I attempted to fetch a response from the server using the following code: response = httpx.post(
"https://page.kakao.com/graphql",
json=post_data,
headers=graphql_headers,
) Full code that contains unnecessary informationimport httpx
graphql_headers = {
"Accept": "application/graphql+json, application/json",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "ko,en-US;q=0.9,en;q=0.8",
"Cache-Control": "no-cache",
"Content-Length": "4371",
"Content-Type": "application/json",
"Dnt": "1",
"Origin": "https://page.kakao.com",
"Pragma": "no-cache",
"Referer": "https://page.kakao.com/content/53397318/viewer/53486401",
"Sec-Ch-Ua": '"Not/A)Brand";v="99", "Microsoft Edge";v="115", "Chromium";v="115"',
"Sec-Ch-Ua-Mobile": "?0",
"Sec-Ch-Ua-Platform": '"Windows"',
"Sec-Fetch-Dest": "empty",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Site": "same-origin",
"Sec-Gpc": "1",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36",
}
webtoon_id = 53397318
query = "\n query contentHomeProductList($after: String, $before: String, $first: Int, $last: Int, $seriesId: Long!, $boughtOnly: Boolean, $sortType: String) {\n contentHomeProductList(\n seriesId: $seriesId\n after: $after\n before: $before\n first: $first\n last: $last\n boughtOnly: $boughtOnly\n sortType: $sortType\n ) {\n totalCount\n pageInfo {\n hasNextPage\n endCursor\n hasPreviousPage\n startCursor\n }\n selectedSortOption {\n id\n name\n param\n }\n sortOptionList {\n id\n name\n param\n }\n edges {\n cursor\n node {\n ...SingleListViewItem\n }\n }\n }\n}\n \n fragment SingleListViewItem on SingleListViewItem {\n id\n type\n thumbnail\n showPlayerIcon\n isCheckMode\n isChecked\n scheme\n row1\n row2\n row3 {\n badgeList\n text\n }\n single {\n productId\n ageGrade\n id\n isFree\n thumbnail\n title\n slideType\n operatorProperty {\n isTextViewer\n }\n }\n isViewed\n eventLog {\n ...EventLogFragment\n }\n}\n \n\n fragment EventLogFragment on EventLog {\n fromGraphql\n click {\n layer1\n layer2\n setnum\n ordnum\n copy\n imp_id\n imp_provider\n }\n eventMeta {\n id\n name\n subcategory\n category\n series\n provider\n series_id\n type\n }\n viewimp_contents {\n type\n name\n id\n imp_area_ordnum\n imp_id\n imp_provider\n imp_type\n layer1\n layer2\n }\n customProps {\n landing_path\n view_type\n helix_id\n helix_yn\n helix_seed\n content_cnt\n event_series_id\n event_ticket_type\n play_url\n banner_uid\n }\n}\n "
post_data = {
"operationName": "contentHomeProductList",
"query": query,
"variables": {
"seriesId": webtoon_id,
"after": "0",
"boughtOnly": False,
"sortType": "asc",
},
}
response = httpx.post(
"https://page.kakao.com/graphql",
json=post_data,
headers=graphql_headers,
)
print(response.text) When I executed the code, the following error occurred.
When I replaced httpx with requests, I was able to execute the code without any errors. The relevant figures observed when using requests are as follows:
The problem persists in the latest version, and the same error occurs after reinstallation using Is this an error with httpx, or is there something I can do to address it? Thank you in advance. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Ah yeah, you're seeing an error because you're including an incorrect (Otherwise we'll treat this as the desired behavior) |
Beta Was this translation helpful? Give feedback.
It's the request header that you're including (in
graphql_headers
) that's the issue, not the response. You don't needContent-Length
there. 🙂