Forums

Run "python manage.py search_index --rebuild" command from pythonanywhere bash console

Hi, I have setup my web app communication with Elasticsearch. Now I have to build the index on my elasticsearch instance, whenever I try to run the command "python manage.py search_index --rebuild", it returns the following error on the console

raise HTTP_EXCEPTIONS.get(meta.status, ApiError)(
elasticsearch.AuthorizationException: AuthorizationException(403

Looks like an authorization issue -- check if connection to your Elasticsearch instance is set up correctly.

I have set up elasticsearch on ec2(AWS) instance, I have run this command from my local PC and data has been indexed on elasticsearch. After that I push the code and deploy it on pythonanywhere, now this command giving me this error. Connection is set up correctly, that's why data is being indexed from local environment

You can see the error here in this video

Looks like credentials you use there are either not correct or do not allow to perform the operation you try to perform.

Why it's working from local machine

Make sure if the authorization is not requiring some interactive behavior or additional steps that you performed on your local machine.

I didn't perform any additional step on my local machine. I am using same elastic user from my local machine and it's building index on ec2 but with same credentials from pythonanywhere it's giving me the error

Then you need to do something to ensure that the authorization is correct. It could be anything - perhaps there's a file that holds the auth information that is not on PythonAnywhere or AWS is only configured to accept connections from certain IPs. This is not something that we can debug for you.