crobertsbmw / deckofcards

An API to simulate a deck of cards
MIT License
1.34k stars 335 forks source link

Docker Container 400 bad request error #81

Open njseeber1 opened 4 years ago

njseeber1 commented 4 years ago

Hey, when spinning up the docker container you have in the code I always get a 400 Bad Request error when making an API request that is in the documentation. Any idea on what might be going on there?

crobertsbmw commented 4 years ago

TBH, I don’t remember setting up any docker stuff. I remember tinkering with docker like 4 years ago, but my familiarity with docker probably rounds to 0. I should probably just remove anything referencing docker in the code.

On Wed, May 6, 2020 at 6:11 PM Nick Seeber notifications@github.com wrote:

Hey, when spinning up the docker container you have in the code I always get a 400 Bad Request error when making an API request that is in the documentation. Any idea on what might be going on there?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/crobertsbmw/deckofcards/issues/81, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABMQLHT3BVXQF2VGSCJYKNLRQH4EVANCNFSM4M24D5VA .

njseeber1 commented 4 years ago

Gotcha, thanks for the update! I Appreciate it!

neno91 commented 3 years ago

TBH, I don’t remember setting up any docker stuff. I remember tinkering with docker like 4 years ago, but my familiarity with docker probably rounds to 0. I should probably just remove anything referencing docker in the code. On Wed, May 6, 2020 at 6:11 PM Nick Seeber @.***> wrote: Hey, when spinning up the docker container you have in the code I always get a 400 Bad Request error when making an API request that is in the documentation. Any idea on what might be going on there? — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub <#81>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABMQLHT3BVXQF2VGSCJYKNLRQH4EVANCNFSM4M24D5VA .

Hello

There is nothing wrong with the dockerfile.

I'ts just the CORS policy thats blocking your requests.

You need to edit spades/settings.py file and insert your host to ALLOWED_HOSTS ALLOWED_HOSTS = ['.deckofcardsapi.com', '127.0.0.1', 'yourhosthere']

Best regards Jørgen S.

crobertsbmw commented 3 years ago

I know this is super old, but I dug into this a little bit today. I couldn't find an error with CORS, but I was able to find a CSRF error when trying to do post requests. I removed the CSRF validation, and now you should be able to make cross site requests. Let me know if that's not he case.

neno91 commented 3 years ago

I know this is super old, but I dug into this a little bit today. I couldn't find an error with CORS, but I was able to find a CSRF error when trying to do post requests. I removed the CSRF validation, and now you should be able to make cross site requests. Let me know if that's not he case.

Thank you :) For me adding my hostname/domain to the allowed_hosts fixed the 400 error.

I cant say if thats the same issue that the thread starter was experiencing. But normally docker acts the same for all parties.

I would assume that you could reproduce the error by just spinning up a docker container on another host and then try to access it.

I was wrong to say its the cors policy. Seems like django now requires the hosting domain to be in the list. https://docs.djangoproject.com/en/3.1/ref/settings/#std:setting-ALLOWED_HOSTS

Best regards Jørgen S.