Code Monkey home page Code Monkey logo

Comments (16)

Dreamsorcerer avatar Dreamsorcerer commented on June 29, 2024

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.

JoeanAmier avatar JoeanAmier commented on June 29, 2024
    @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.

Dreamsorcerer avatar Dreamsorcerer commented on June 29, 2024

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.

JoeanAmier avatar JoeanAmier commented on June 29, 2024

Replacing aiohttp with https or requests can solve the problem.

from aiohttp.

Dreamsorcerer avatar Dreamsorcerer commented on June 29, 2024

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.

JoeanAmier avatar JoeanAmier commented on June 29, 2024

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.

Dreamsorcerer avatar Dreamsorcerer commented on June 29, 2024

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.

JoeanAmier avatar JoeanAmier commented on June 29, 2024

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.

JoeanAmier avatar JoeanAmier commented on June 29, 2024

I recorded a video, including the location and results of the anomalies, as well as the results of individual tests.

https://youtu.be/v7b8NiqbrrY

If you think this anomaly is not related to aiohttp, I will delete the video.

from aiohttp.

JoeanAmier avatar JoeanAmier commented on June 29, 2024

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.

Dreamsorcerer avatar Dreamsorcerer commented on June 29, 2024

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.

JoeanAmier avatar JoeanAmier commented on June 29, 2024

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.

JoeanAmier avatar JoeanAmier commented on June 29, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.