Jump to content

500 server error


hygorfragas

Recommended Posts

hygorfragas

/user_usage_stats/session_list

 

Hi guys, as you can see I'm focused on the emby api. today I came across error 500 (server error) when I make the request via postman, browser etc... I always have the return 500 error and the body: Object reference not set to an instance of an object.
With the swagger it's success! I've been looking in git and documentation but to no avail, apparently the request doesn't require anything special. can you help me ? follows the structure of url and log (attached)

http://ip-server/emby/user_usage_stats/session_list?api_key=chave-api

embyserver.txt

Link to comment
Share on other sites

@TeamB this is actually one of your api's so i'll have to defer to you for comment. If you're not intending for these to be used by others then you can always hide them with the IsHidden property on the route declaration.

Link to comment
Share on other sites

hygorfragas
5 minutes ago, Luke said:

@TeamB this is actually one of your api's so i'll have to defer to you for comment. If you're not intending for these to be used by others then you can always hide them with the IsHidden property on the route declaration.

Sorry, did I expose any data?

Link to comment
Share on other sites

Just now, hygorfragas said:

Sorry, did I expose any data?

No you didn't. The api you're referencing here is actually part of the playback reporting plugin and not the core server, therefore I need to pull the developer into this conversation in order to comment on it.

Link to comment
Share on other sites

hygorfragas
2 minutes ago, Luke said:

No you didn't. The api you're referencing here is actually part of the playback reporting plugin and not the core server, therefore I need to pull the developer into this conversation in order to comment on it.

A yes, I appreciate it if they return then. I appreciate your help

Link to comment
Share on other sites

TeamB

You are correct it does not require any params

https://github.com/faush01/playback_reporting/blob/e0d169459a5c3177355e5aa924eeda67cb0ce3c3/playback_reporting/Api/UserActivityAPI.cs#L41

The API just returns a list of session info, this end point is Admin only so the user needs to be an admin

https://github.com/faush01/playback_reporting/blob/e0d169459a5c3177355e5aa924eeda67cb0ce3c3/playback_reporting/Api/UserActivityAPI.cs#L902

The 500 Error stack

	System.NullReferenceException: System.NullReferenceException: Object reference not set to an instance of an object.
	   at Emby.Server.Implementations.Library.UserManager.GetUserPolicy(User user)
	   at playback_reporting.Api.UserActivityAPI.Get(GetSessionInfo request)
	   at Emby.Server.Implementations.Services.ServiceController.Execute(HttpListenerHost appHost, Object requestDto, IRequest req)
	   at Emby.Server.Implementations.Services.ServiceHandler.ProcessRequestAsync(HttpListenerHost appHost, IRequest httpReq, IResponse httpRes, RestPath restPath, String responseContentType, CancellationToken cancellationToken)
	   at Emby.Server.Implementations.HttpServer.HttpListenerHost.RequestHandler(IRequest httpReq, ReadOnlyMemory`1 urlString, ReadOnlyMemory`1 localPath, CancellationToken cancellationToken)
	Source: Emby.Server.Implementations
	TargetSite: MediaBrowser.Model.Users.UserPolicy GetUserPolicy(MediaBrowser.Controller.Entities.User)

 

Emby.Server.Implementations.Library.UserManager.GetUserPolicy(User user)

User is probably null

https://github.com/faush01/playback_reporting/blob/e0d169459a5c3177355e5aa924eeda67cb0ce3c3/playback_reporting/Api/UserActivityAPI.cs#L907

So

AuthorizationInfo user_info = _ac.GetAuthorizationInfo(Request);

is returning no user.

@Luke Does AuthorizationContext.GetAuthorizationInfo(Request) work with API KEYS?

 

 

Link to comment
Share on other sites

hygorfragas
11 minutes ago, TeamB said:

You are correct it does not require any params

https://github.com/faush01/playback_reporting/blob/e0d169459a5c3177355e5aa924eeda67cb0ce3c3/playback_reporting/Api/UserActivityAPI.cs#L41

The API just returns a list of session info, this end point is Admin only so the user needs to be an admin

https://github.com/faush01/playback_reporting/blob/e0d169459a5c3177355e5aa924eeda67cb0ce3c3/playback_reporting/Api/UserActivityAPI.cs#L902

The 500 Error stack


	System.NullReferenceException: System.NullReferenceException: Object reference not set to an instance of an object.
	   at Emby.Server.Implementations.Library.UserManager.GetUserPolicy(User user)
	   at playback_reporting.Api.UserActivityAPI.Get(GetSessionInfo request)
	   at Emby.Server.Implementations.Services.ServiceController.Execute(HttpListenerHost appHost, Object requestDto, IRequest req)
	   at Emby.Server.Implementations.Services.ServiceHandler.ProcessRequestAsync(HttpListenerHost appHost, IRequest httpReq, IResponse httpRes, RestPath restPath, String responseContentType, CancellationToken cancellationToken)
	   at Emby.Server.Implementations.HttpServer.HttpListenerHost.RequestHandler(IRequest httpReq, ReadOnlyMemory`1 urlString, ReadOnlyMemory`1 localPath, CancellationToken cancellationToken)
	Source: Emby.Server.Implementations
	TargetSite: MediaBrowser.Model.Users.UserPolicy GetUserPolicy(MediaBrowser.Controller.Entities.User)

 

Emby.Server.Implementations.Library.UserManager.GetUserPolicy(User user)

User is probably null

https://github.com/faush01/playback_reporting/blob/e0d169459a5c3177355e5aa924eeda67cb0ce3c3/playback_reporting/Api/UserActivityAPI.cs#L907

So

AuthorizationInfo user_info = _ac.GetAuthorizationInfo(Request);

is returning no user.

@Luke Does AuthorizationContext.GetAuthorizationInfo(Request) work with API KEYS?

 

 

Can I send this admin user id in the header?

Link to comment
Share on other sites

hygorfragas
1 minute ago, hygorfragas said:

Can I send this admin user id in the header?

what is strange is that the user who created the api key has to have admin access to the panel, and my user is admin the strange thing is because he did not authorize

Link to comment
Share on other sites

hygorfragas
15 minutes ago, TeamB said:

You are correct it does not require any params

https://github.com/faush01/playback_reporting/blob/e0d169459a5c3177355e5aa924eeda67cb0ce3c3/playback_reporting/Api/UserActivityAPI.cs#L41

The API just returns a list of session info, this end point is Admin only so the user needs to be an admin

https://github.com/faush01/playback_reporting/blob/e0d169459a5c3177355e5aa924eeda67cb0ce3c3/playback_reporting/Api/UserActivityAPI.cs#L902

The 500 Error stack


	System.NullReferenceException: System.NullReferenceException: Object reference not set to an instance of an object.
	   at Emby.Server.Implementations.Library.UserManager.GetUserPolicy(User user)
	   at playback_reporting.Api.UserActivityAPI.Get(GetSessionInfo request)
	   at Emby.Server.Implementations.Services.ServiceController.Execute(HttpListenerHost appHost, Object requestDto, IRequest req)
	   at Emby.Server.Implementations.Services.ServiceHandler.ProcessRequestAsync(HttpListenerHost appHost, IRequest httpReq, IResponse httpRes, RestPath restPath, String responseContentType, CancellationToken cancellationToken)
	   at Emby.Server.Implementations.HttpServer.HttpListenerHost.RequestHandler(IRequest httpReq, ReadOnlyMemory`1 urlString, ReadOnlyMemory`1 localPath, CancellationToken cancellationToken)
	Source: Emby.Server.Implementations
	TargetSite: MediaBrowser.Model.Users.UserPolicy GetUserPolicy(MediaBrowser.Controller.Entities.User)

 

Emby.Server.Implementations.Library.UserManager.GetUserPolicy(User user)

User is probably null

https://github.com/faush01/playback_reporting/blob/e0d169459a5c3177355e5aa924eeda67cb0ce3c3/playback_reporting/Api/UserActivityAPI.cs#L907

So

AuthorizationInfo user_info = _ac.GetAuthorizationInfo(Request);

is returning no user.

@Luke Does AuthorizationContext.GetAuthorizationInfo(Request) work with API KEYS?

 

 

and in the swegger it tells me that you just need to be a user. (with the api key, of course)

Link to comment
Share on other sites

TeamB

It does not look like api_key is supported for addon API endpoints from what I can see.

you can auth and create an API key for a user and then send that as the token auth header.

@Luke can confirm on the api_key not working with plugin API endpoints and the AuthorizationContext

Link to comment
Share on other sites

hygorfragas
47 minutes ago, TeamB said:

It does not look like api_key is supported for addon API endpoints from what I can see.

you can auth and create an API key for a user and then send that as the token auth header.

@Luke can confirm on the api_key not working with plugin API endpoints and the AuthorizationContext

can you show me an example of how this would look?

Link to comment
Share on other sites

hygorfragas

image.thumb.png.3fabf7221f4e4619764a6bb03a9ba444.png

 

 

image.thumb.png.4d215e82a72fa95fa1dc079dd1742b37.png

 

In my test and work tool I have these fields to work with, do any of these options serve to do this? @TeamB

Edited by hygorfragas
Link to comment
Share on other sites

TeamB

There is some code (python) here that logs in a gets an auth token

https://github.com/faush01/EmbyToolbox/blob/c6a0453cd977e882f11178798e42eecaf20358f2/WatchedStatusBackup/emby_client.py#L7

and you can use it in your request like this

https://github.com/faush01/EmbyToolbox/blob/c6a0453cd977e882f11178798e42eecaf20358f2/WatchedStatusBackup/emby_client.py#L32

There used to be a dev Wiki but I cant find it any longer, @Luke can probably answer any of your auth questions.

 

 

Link to comment
Share on other sites

hygorfragas
24 minutes ago, TeamB said:

There is some code (python) here that logs in a gets an auth token

https://github.com/faush01/EmbyToolbox/blob/c6a0453cd977e882f11178798e42eecaf20358f2/WatchedStatusBackup/emby_client.py#L7

and you can use it in your request like this

https://github.com/faush01/EmbyToolbox/blob/c6a0453cd977e882f11178798e42eecaf20358f2/WatchedStatusBackup/emby_client.py#L32

There used to be a dev Wiki but I cant find it any longer, @Luke can probably answer any of your auth questions.

 

 

Well, I don't know how to use this in my application, because there's nowhere to fit it there.  I'll wait for the @Lukeanswer the other questions, sometimes he has an easier solution. but as I understand @TeamB I need a token that "proves" that I'm an admin. And I need to send this token where?

Link to comment
Share on other sites

hygorfragas
12 hours ago, hygorfragas said:

Well, I don't know how to use this in my application, because there's nowhere to fit it there.  I'll wait for the @Lukeanswer the other questions, sometimes he has an easier solution. but as I understand @TeamB I need a token that "proves" that I'm an admin. And I need to send this token where?

Help please 

Link to comment
Share on other sites

hygorfragas
18 hours ago, hygorfragas said:

Well, I don't know how to use this in my application, because there's nowhere to fit it there.  I'll wait for the @Lukeanswer the other questions, sometimes he has an easier solution. but as I understand @TeamB I need a token that "proves" that I'm an admin. And I need to send this token where?

can you give me a hint about this @TeamB

Link to comment
Share on other sites

TeamB

I am not sure i can help, you need to authenticate and get an access token that you then use in the header, the example i gave is in python but the steps are the same no matter what language you are using.

hopefully luke will have answers on some of the other questions

Link to comment
Share on other sites

hygorfragas

 does this token have to go together in the header? Can you show me the structure of the URL? maybe I can turn around. this token is the admin user token is that it?

Link to comment
Share on other sites

hygorfragas
2 minutes ago, TeamB said:

This is how the python code I lined above does it

https://github.com/faush01/EmbyToolbox/blob/c6a0453cd977e882f11178798e42eecaf20358f2/WatchedStatusBackup/backup.py#L23

The code is a simple example of how to request an access token for a user and then use it in the headers to make a request.

Is this data generated by the server (unique) or is it just me to find out the admin user id? I can already collect the users id!

Link to comment
Share on other sites

hygorfragas
18 hours ago, TeamB said:

You dont need the user id, just the username and password to request an access token

Hello @TeamB

Sorry for the delay, in the end I think I'm on the way.
I recently did the tests for capturing the token in postman I got an incorrect username and password (which isn't)
analyzing the server log I noticed that it generated the token but gave some error. can you help me? the postman call images are below along with the server log image with the response.

log.png

 

image.png.8de582d74d7e92792e667dc19358c363.png

 

InkedCaptura de tela 2021-08-24 175648_LI.jpg

Edited by hygorfragas
Link to comment
Share on other sites

Hi.  It looks like you are putting the parameters that are supposed to be in the auth header as url params.  Look closely at the Swagger doc for that call and be sure and get the x-emby-authorization header correct.

You also shouldn't have a userID on an authenticate by name call although I doubt that is causing a problem.

https://github.com/MediaBrowser/Emby/wiki/User-Authentication

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...