Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

在异步请求中,webuiapi.py中的async_post 方法中session.post没将header传过去,导致通过api token方式无法用异步调用。 #185

Open
ak18cn opened this issue Oct 25, 2024 · 0 comments

Comments

@ak18cn
Copy link

ak18cn commented Oct 25, 2024

api = webuiapi.WebUIApi(baseurl=SD_BASE_URL)  
api.session.headers.update({'Authorization': 'Bearer ' +SD_ACCESS_TOKEN})   
api.txt2img(,,use_async=True) #Authorization failed
api.txt2img(,,use_async=False) #OK

#webuiapi.py:

def post_and_get_api_result(self, url, json, use_async):
        if use_async:
            import asyncio

            return asyncio.ensure_future(self.async_post(url=url, json=json))
        else:
            response = self.session.post(url=url, json=json)
            return self._to_api_result(response)

    async def async_post(self, url, json):
        import aiohttp

        async with aiohttp.ClientSession(timeout=aiohttp.ClientTimeout()) as session:
            infinite_timeout = aiohttp.ClientTimeout(total=None)
            auth = aiohttp.BasicAuth(self.session.auth[0], self.session.auth[1]) if self.session.auth else None
            async with session.post(url, json=json, auth=auth, timeout=infinite_timeout) as response: # infinite_timeout timeout here for timeout fix
                return await self._to_api_result_async(response)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant