adamchainz / django-cors-headers

Django app for handling the server headers required for Cross-Origin Resource Sharing (CORS)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

'Missing scheme or netloc" for characters in a string

adamchainz opened this issue · comments

@dopeboy reports in #403 (comment) :

I'm getting a bit of a strange error. This is with 3.0.1

This works fine locally:

CORS_ORIGIN_WHITELIST = ['localhost:3000']

But when on production, when I run a manage.py operation, I get:

SystemCheckError: System check identified some issues:

ERRORS:
?: (corsheaders.E013) Origin '/' in CORS_ORIGIN_WHITELIST is missing scheme or netloc
?: (corsheaders.E013) Origin '/' in CORS_ORIGIN_WHITELIST is missing scheme or netloc
?: (corsheaders.E013) Origin '0' in CORS_ORIGIN_WHITELIST is missing scheme or netloc
?: (corsheaders.E013) Origin '0' in CORS_ORIGIN_WHITELIST is missing scheme or netloc
?: (corsheaders.E013) Origin '0' in CORS_ORIGIN_WHITELIST is missing scheme or netloc
?: (corsheaders.E013) Origin '3' in CORS_ORIGIN_WHITELIST is missing scheme or netloc
?: (corsheaders.E013) Origin ':' in CORS_ORIGIN_WHITELIST is missing scheme or netloc
?: (corsheaders.E013) Origin ':' in CORS_ORIGIN_WHITELIST is missing scheme or netloc
?: (corsheaders.E013) Origin 'a' in CORS_ORIGIN_WHITELIST is missing scheme or netloc
?: (corsheaders.E013) Origin 'c' in CORS_ORIGIN_WHITELIST is missing scheme or netloc
?: (corsheaders.E013) Origin 'h' in CORS_ORIGIN_WHITELIST is missing scheme or netloc
?: (corsheaders.E013) Origin 'h' in CORS_ORIGIN_WHITELIST is missing scheme or netloc
?: (corsheaders.E013) Origin 'l' in CORS_ORIGIN_WHITELIST is missing scheme or netloc
?: (corsheaders.E013) Origin 'l' in CORS_ORIGIN_WHITELIST is missing scheme or netloc
?: (corsheaders.E013) Origin 'o' in CORS_ORIGIN_WHITELIST is missing scheme or netloc
?: (corsheaders.E013) Origin 'o' in CORS_ORIGIN_WHITELIST is missing scheme or netloc
?: (corsheaders.E013) Origin 'p' in CORS_ORIGIN_WHITELIST is missing scheme or netloc
?: (corsheaders.E013) Origin 's' in CORS_ORIGIN_WHITELIST is missing scheme or netloc
?: (corsheaders.E013) Origin 't' in CORS_ORIGIN_WHITELIST is missing scheme or netloc
?: (corsheaders.E013) Origin 't' in CORS_ORIGIN_WHITELIST is missing scheme or netloc
?: (corsheaders.E013) Origin 't' in CORS_ORIGIN_WHITELIST is missing scheme or netloc

This doesn't work locally:

CORS_ORIGIN_WHITELIST = ['http://localhost:3000']

Hey

Are you sure you're running the same version of django-cors-headers both locally and in production? The system check error was added in version 3.0.0 , you will need the scheme from that version onwards. You might have gotten different versions by not pinning your requirements to exact versions and installing in production after the 3.0.0 release went out, even though locally you installed before it went out. Always pin!

It's weird you're seeing the error for every character in a string. There's a check before doing that check that the value of the setting is an iterable of strings: https://github.com/ottoyiu/django-cors-headers/blob/master/corsheaders/checks.py#L58 .

I think the best step forwards is for you to recreate the error in the django-cors-headers test suite. You can add a test to this file: https://github.com/ottoyiu/django-cors-headers/blob/master/tests/test_checks.py#L67 and run the tests with tox.

Thanks for creating a new issue for me, @adamchainz.

This is from a fresh install where my versions are unpinned (which I'll eventually fix) in my Pipfile (I'm using pipenv). I made the local and production environments yesterday. On both local and production, I see something like so in Pipfile.lock:

        "django-cors-headers": {
            "hashes": [
                "sha256:0ac81a9a70ba9bf5569f19693f1ce566e46cabc710cdaa053409415c690033bb",
                "sha256:b57087e45e4418a6147b8a27ca9d19da2c16b3e4732b2372fe2d9774fc7c5bca"
            ],
            "index": "pypi",
            "version": "==3.0.1"
        },

I think the best step forwards is for you to recreate the error in the django-cors-headers test suite.

OK, will do when I get the time. For time's sake, I'm rolling with allowing all origins for now.

To pin, just commit Pipfile.lock https://pipenv.readthedocs.io/en/latest/basics/#general-recommendations-version-control

If you really are using the same versions and settings in both environments, it may be that you've missed other things, such as installing the middleware or app for one of your environments: https://github.com/ottoyiu/django-cors-headers#setup

Sorry, should have explained that more fully - I am committing Pipfile.lock.

I'm pretty sure I haven't - my settings.py is identical between the two environments (aside from alternative env var's are loaded at runtime).

Try running ./manage.py check on both environments. It should run implicitly locally under runserver but maybe you're not seeing the check result there.

Can you check with the latest version 3.0.2?

Just add , for host name tail in CORS_ORIGIN_WHITELIST on settings.py

like this

CORS_ORIGIN_WHITELIST = (
    'http://localhost:8080',
)

@dopeboy 's report shows [] which creates a list that doesn't have the same problem as ('x') being a string and ('x',) being a tuple

commented

I'm getting the same weird error after pipenv installing.

@SHxKM please paste the error message and your relevant settings

@adamchainz, thanks for being so diligent here. As someone who helps maintain another project, I know the effort that goes into monitoring these issues.

I completely rebuilt my pip library. My pipfile.lock is:

        "django-cors-headers": {
            "hashes": [
                "sha256:5b80bf0f8d7fc6e2bcb4f40781d5ff3661961bbf1982e52daec77241dea3b890",
                "sha256:ebf3e2cf25aa6993b959a8e6a87828ebb3c8fe5bc3ec4a2d6e65f3b8d9b4212c"
            ],
            "index": "pypi",
            "version": "==3.0.2"
        },

Locally, I can confirm this doesn't work (expected):

CORS_ORIGIN_WHITELIST = [      
    'localhost:3000'
]   

And this does work (expected):

CORS_ORIGIN_WHITELIST = [      
    'http://localhost:3000'
]   

I also tested on production with my URL and it works as expected - no longer getting those netloc errors. Not sure if there was something wrong with my pip install or if the new version fixed something but all is well for me. @SHxKM - want to try completely clearing your pip lib and reinstalling?

Thanks again for your support.

Closing because original issue fixed. @SHxKM I'm sure you can figure this out by installing the right versions and tidying your settings file.

i face this error till now after doing all those stuffs `please help me
error

@RupokShahriar please open a new issue with your settings file.

what is issue? please tell me sir

now what i do ?

@dopeboy 's report shows [] which creates a list that doesn't have the same problem as ('x') being a string and ('x',) being a tuple

It works! Was fixed! Just put a comma at the end