Comments (16)
Due to the unique nature of the project, it is not convenient for others to reproduce the bug.
I am testing the TikTok download feature of the project and reproducing the bug 100%.
Could you atleast put a snippet of the code you used along with comments explaining what happened at different points? I'm rather struggling to understand your issue from the description.
from aiohttp.
@PrivateRetry.retry
async def request_file(
self,
url: str,
temp: Path,
actual: Path,
show: str,
id_: str,
count: SimpleNamespace,
progress: Progress,
headers: dict = None,
tiktok=False,
unknown_size=False,
semaphore: Semaphore = None,
) -> bool:
async with semaphore or self.semaphore:
try:
async with self.session.get(
url,
proxy=self.proxy_tiktok if tiktok else self.proxy,
headers=self.__adapter_headers(headers, tiktok, ), ) as response:
if not (
content := int(
response.headers.get(
'content-length',
0))) and not unknown_size: # 响应内容大小判断
self.log.warning(f"{url} 响应内容为空")
return False
if response.status > 400: # 响应码判断
self.log.warning(
f"{response.url} 响应码异常: {response.status}")
return False
elif all((self.max_size, content, content > self.max_size)): # 文件下载跳过判断
self.log.info(f"{show} 文件大小超出限制,跳过下载")
return True
return await self.download_file(
temp,
actual,
show,
id_,
response,
content,
count,
progress)
except ClientError as e:
self.log.warning(f"网络异常: {e}")
return False
The ClientSession in this location has encountered an exception. I used a new ClientSession object here to restore it to normal. My friend said that the parameter may not have been successfully passed. The code here is to download a file and requires a cookie. The normal response code is 206, and the incorrect cookie response code is 403. It is suspected that the headers were not successfully passed here.
from aiohttp.
I'm still not clear what the issue is.
I used a new ClientSession object here to restore it to normal.
The code you shared does not create a new ClientSession, it simply returns False after an exception.
I'm rather unclear what you want us to do. If the headers are wrong, that's not something we can help with...
from aiohttp.
Replacing aiohttp with https or requests can solve the problem.
from aiohttp.
Are you putting parameters in the URL? The most common difference between those libraries is that URLs are escaped by default. See (in particular, the note): https://docs.aiohttp.org/en/stable/client_quickstart.html#passing-parameters-in-urls
from aiohttp.
I used aiohttp in my project, and at the location where an exception occurred, I passed in the URL and headers parameters. I copied the URL and headers parameters and tested them using aiohttp code. The test passed, but I suspect that parameter passing failed. My friend has also experienced parameter passing failures, which is not a coding issue. If the headers parameter is not passed, the running result will be the same as this exception result.
from aiohttp.
I don't think there's any difference between these libraries regarding passing headers. You're either passing them or you're not. aiohttp isn't going to lose headers.
from aiohttp.
Testing the URL and headers parameters using aiohttp, httpx, and requests separately is normal, and aiohttp only experiences exceptions at a specific location in the project.
from aiohttp.
I recorded a video, including the location and results of the anomalies, as well as the results of individual tests.
If you think this anomaly is not related to aiohttp, I will delete the video.
from aiohttp.
If it's a problem with my code, I should get a response code 403 when testing using URL and headers, which is consistent with the response code at the exception location. However, the response code I tested was 206, indicating that it's not an exception in my code.
from aiohttp.
The URL in your video is a string with query parameters. Therefore, you probably need to pre-encode (or pass them using params
) as I mentioned in the previous comment: #8464 (comment)
The difference in behaviour could be the proxy? Maybe one proxy is actually decoding the URL before passing it through to the endpoint, while the other passes it through unchanged.
from aiohttp.
The URL and headers are both directly copied for testing, and the proxy is also set to http://127.0.0.1:10809 If it is a coding issue, the copied test results should be consistent with the abnormal results.
from aiohttp.
The code at the exception location and the parameters used in the test code are exactly the same, and the results should also be consistent, but in reality, they are not consistent. I don't know why the headers failed to pass, but as an aiohttp developer, you should have a better understanding.
from aiohttp.
Related Issues (20)
- ValueError: I/O operation on closed file on WSL HOT 2
- Security improvement: raise_for_status + ClientError prevent tokens from leaking HOT 5
- Broken HTTP request parsing: Upgrade: h2c header leads to discarded body HOT 7
- aiohttp does not support concurrent requests exceeding 500.
- Termux aiohttp could not build wheels for aiohttp HOT 5
- aiohttp cannot make HTTPS (SSL) requests in a Windows container HOT 10
- DNS over HTTPS (DoH) HOT 1
- Unmonitored websocket task triggers false errors in logs HOT 1
- Documentation not working HOT 1
- https://docs.aiohttp.org/ has been defaced/squatted HOT 1
- aiohttp.org site is down HOT 1
- Server; POST-request; BadStatusLine: 400; an endless stream of exception messages that have no impact on operation.
- Broken timeout system with ws_connect HOT 1
- graceful shutdown order and cleanup contexts HOT 7
- ValueError: I/O operation on closed file in aiohttp payload size property on file uploading using form HOT 1
- Allow reading already retrieved response body after connection is closed
- Support for sending Trailer headers HOT 2
- Separate exception for DNS errors
- Weak Etag can not trigger negotiation caching
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aiohttp.