django-cors-headers: 'Missing scheme or netloc" for characters in a string

@dopeboy reports in https://github.com/ottoyiu/django-cors-headers/issues/403#issuecomment-494656909 :

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']

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 18 (9 by maintainers)

Most upvoted comments

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

like this

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

@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.

@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