-
Notifications
You must be signed in to change notification settings - Fork 57
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
Problems with aiohttp 3.0.1 #155
Comments
Actually with the following code CORS doesn't work even for 2.3.10: for resource in app.router.resources():
cors.add(resource) |
Route definition: @routes.post('/api/users')
async def create_user(request: Request):
return web.json_response(status=web.HTTPCreated.status_code) |
We have the issue here, have you found a workaround? |
Guys, the library has several technical debts. |
Ok thanks for your answer! |
Fixed by #160 |
I hate to be that guy, but will there be a new release to PyPI? I see there was a commit to bump the version, but I don't see it published yet. Thanks :) |
Thanks for remember. |
Having following error:
with: same code works for aiohttp 2 and aiohttp-cors 0.6.0. Is there real example of adding routes to cors that do work and was tested? |
Here |
btw. Adding to cors with both methods doesn't help:
|
The same for me. Rolled back to aiohttp 2 and aiohttp_cors 0.6.0 |
Same here. aiohttp 2.0 + aiohttp-cors 0.6.0 seems to be a good solution for now. |
Guys, if somebody wants to provide a PR -- you are welcome. |
@asvetlov I'll try to look into it over the weekend. Btw, for me, this only happens on localhost, all other places work fine. |
Cool! |
I could make some progress to solve this problem. import asyncio
import aiohttp
import aiohttp_cors
from aiohttp.web_runner import GracefulExit
async def handler(request):
return aiohttp.web.Response(
text="Hello!",
headers={
"X-Custom-Server-Header": "Custom data",
})
app = aiohttp.web.Application()
cors = aiohttp_cors.setup(app, defaults={
"http://request-from": aiohttp_cors.ResourceOptions(
allow_credentials=True,
expose_headers="*",
allow_headers="*",
),
})
routes = [{
'method': 'GET',
'path': '/test',
'handler': handler,
'name': 'test-good'
}, {
'method': 'POST',
'path': '/test',
'handler': handler,
'name': 'test-good'
}, {
'method': 'GET',
'path': '/test-bad',
'handler': handler,
'name': 'test-bad-get'
}, {
'method': 'POST',
'path': '/test-bad',
'handler': handler,
'name': 'test-bad-post'
}, ]
for route in routes:
cors.add(
app.router.add_route(
method=route['method'],
path=route['path'],
handler=route['handler'],
name=route['name']
)
)
loop = asyncio.get_event_loop()
handler = app._make_handler()
server = loop.run_until_complete(
loop.create_server(
handler,
host='localhost',
port='8081'
)
)
try:
loop.run_forever()
except (GracefulExit, KeyboardInterrupt):
pass
finally:
loop.stop()
For
we will get some thing like that:
But for OPTION request to url /test-bad
will return every time:
So we try to find method |
That's interesting. Would be nice to fix |
I have this problem also. I'm keeping with aiohttp 2.3.10. Thanks. |
aiohttp-3.3.2 + aiohttp-cors-0.7.0 works fine too! <3 |
Hey guys ! I think i have the same issue. @valentinmk did you find a workaround ? |
@TTRh I used the above mentioned versions and it worked. Unfortunately I was not able to make it work with the latest version. |
That sucks... :/
… |
Hum only rollbacking to aiohttp 2 worked for me :/ |
This code worked for me with aiohttp 3.5.4, aiohttp-cors 0.7.0 |
up) |
Pull Request for aiohttp-cors is welcome! |
I'm faced with this issue with POST requests and CORS also, but everything works fine with this code: from aiohttp_cors import setup as cors_setup, ResourceOptions
...
routes = [
web.get("/", handle),
web.post("/something", another_handle),
]
app.router.add_routes(routes)
cors = cors_setup(
app,
defaults={
"*": ResourceOptions(
allow_credentials=True, expose_headers="*", allow_headers="*",
)
},
)
for route in list(app.router.routes()):
cors.add(route) Versions: Maybe this will help someone else with this issue. |
thanks it's work for me |
This code works fine with aiohttp 2.3.10:
curl -H "Origin: http://example.com" -H "Access-Control-Request-Method: POST" -H "Access-Control-Request-Headers: X-Requested-With" -X OPTIONS --verbose localhost:8080/api/users
But following (fixed OPTIONS error, adding routes differently) code fails for aiohttp 3.0.1:
Same cURL request results in:
The text was updated successfully, but these errors were encountered: