Ticket: User Preferences - http PUT 401

When I was trying to save the preference - getting 401 error from the debugger: - - [18/Aug/2020 17:20:23] “GET /api/v1/movies/facet-search?cast=Denzel%20Washington&page=0 HTTP/1.1” 200 - - - [18/Aug/2020 17:20:24] “GET /api/v1/movies/facet-search?cast=Morgan%20Freeman&page=2 HTTP/1.1” 200 - - - [18/Aug/2020 17:20:37] “PUT /api/v1/user/update-preferences HTTP/1.1” 401 - - - [18/Aug/2020 17:20:38] “GET /api/v1/movies/facet-search?cast=Denzel%20Washington&page=0 HTTP/1.1” 200 - - - [18/Aug/2020 17:20:38] “GET /api/v1/movies/facet-search?cast=Morgan%20Freeman&page=2 HTTP/1.1” 200 -

Also see the debug output attached from browser, complains on missing header.

401-error.pdf (50.5 KB)

401 means unauthorized. Check your user’s authorization, it should have read/write access.


thanks for the response. My take below:

I was able to create a sign-up record which means I have both RW access at filesystem and in the database. I did verify few times the permissions and made it open for everybody on the folders.

Just to reconfirm I signed-up again with a new name, email and it has created it successfully. I am pasting the output from run.py during signup and status update and you will see POST during sing-up passed but PUT for user-pref and for logout also failed(which i just realized). - - [26/Aug/2020 05:35:49] “GET /api/v1/movies/facet-search?cast=Denzel%20Washington&page=0 HTTP/1.1” 200 - - - [26/Aug/2020 05:35:49] “GET /api/v1/movies/ HTTP/1.1” 200 - - - [26/Aug/2020 05:35:50] “GET /api/v1/movies/facet-search?cast=Morgan%20Freeman&page=2 HTTP/1.1” 200 - - - [26/Aug/2020 05:36:36] “POST /api/v1/user/login HTTP/1.1” 201 - - - [26/Aug/2020 05:36:37] “GET /api/v1/movies/facet-search?cast=Denzel%20Washington&page=0 HTTP/1.1” 200 - - - [26/Aug/2020 05:36:37] “GET /api/v1/movies/facet-search?cast=Morgan%20Freeman&page=2 HTTP/1.1” 200 - - - [26/Aug/2020 05:37:44] “PUT /api/v1/user/update-preferences HTTP/1.1” 401 - - - [26/Aug/2020 05:37:44] “GET /api/v1/movies/facet-search?cast=Denzel%20Washington&page=0 HTTP/1.1” 200 - - - [26/Aug/2020 05:37:45] “GET /api/v1/movies/facet-search?cast=Morgan%20Freeman&page=2 HTTP/1.1” 200 - - - [26/Aug/2020 05:39:11] “POST /api/v1/user/logout HTTP/1.1” 401 -

Sending you message to share the code.


I am having the same issue, code looks fine, but am getting the “401” http error, same as Suresh. Please help.

Also, when I run the “Preferences” test, I get this error, which doesn’t seem to have anything to do with the code I am changing:

Not sure if this is a separate issue - when i run the test via the web interface, I get the error: “User Preferences: preferences weren’t saved correctly”. All other tests so far I have done through the website and have worked fine.

From your prompt it looks like your virtual env is not activated.

steevej-1495 - Do you mean the “conda mflix” VE? It was active.


Usually, anaconda modifies the prompt to indicate the active virtual environment, such as

(mflix) C:\Temp\...>

Your prompt does not show that. May be yours is different. Sorry.

That’s because I had started the VE in another window. Don’t know why… :slight_smile:
I started in the same window, still get the same error:

And what about the 401 HTTP error I get in the application? Are these two issues linked? I’m stuck at this point in the course till this is resolved.

Have you install the requirements in the same terminal as the one where the VE is installed?

Yes. All the other labs have worked fine.

Hi. So does anyone have any ideas on the HTTP 401 error I am getting? That is the main issue here, and I would really like to finish this course.

kanikasingla - you helped another person before with this - can you share what was done?


I also noticed that when I click the “Logout” link on the website, I also see the HTTP 401 error and the record in the sessions collection is not deleted.
Creating a user works fine, logging in and creating the session record also works, but when calling the “logout” or “update-preferences” methods it fail:

Seems like a permission issue, I checked the “m220student” user account on the cluster, is an admin so should not have any database privilege issues:

I’m really stuck, any help would be very appreciated.

Does pytest -m user_management works without errors?

Hi @steevej-1495 - actually none of the command line tests work - get the same
TypeError: attrib() got an unexpected keyword argument ‘convert’
error as above - but the web based tests work fine.

This may be a separate issue, and I am not that worried about it, as I can successfully test and get a return code, so I have a work around. My main issue is the HTTP 401 error when accessing the two methods I mentioned above.

So I skipped this Lab (not sure why they call it a “Ticket” in the course!) and progressed on with the course. Am in the “Create/Update Comments” section, and am getting the same HTTP 401 error when it calls the “comment” api.

As you can see, the POST calls return an error - except for the “user” API when I created a new user - that works fine. But why are the other POST calls failing?


UPDATE: to rule out user permission issues in the database, I tried using Jupyter to perform an insert into the “comments” collection - which was successful:

This uses the exact same credentials to connect to Atlas as the MFlix app does.

So… what could be throwing a HTTP 401 permissions error?


I did some changes and now all my test has been passing and as well as User_Preferences Ticket also has passed. 401 error still there and preference is not added to the user collection however everything is green…phew & good-luck!

#1 .ini - quoted the superkey
#2 {"$set": {“preferences”:prefs}}

Can you confirm that the user “m220student” in your Atlas database or your local database does have read/write all databases as their permissions?

It is unusual to see a 401 HTTP return code unless there is an aspect of the user permissions incorrectly set.