Jump to content

Help with powershell encoding of api result viewed in vscode debugger


ginjaninja

Recommended Posts

ginjaninja

I am getting back some episodes from /items using powershell. i have tried

$apiresult = Invoke-WebRequest -Uri $apiurl -Method Get
and
$apiresult = Invoke-RestMethod -ContentType 'application/json; charset=utf-8' $apiurl

both give me the data but i notice episodes with special characters show as

Krak�w

rather than

Kraków

when viewed in vscode powershell debugger. (version 7.2).

As a point of learning i would like the response to look right on the screen in vs code.

I think its probably very important to say that when i read episode names from the filing system (get-childitem) in the same script, the episodes' special characters show properly....so vscode is capable of showing the special character but doesnt show special characters properly  for responses from the api.

 

Ive little understanding of character encoding, can any one shed any light on these questions? hopefully they make sense, and might help point me in the right direction please.

  • is the visual discrepancy a character encoding issue? can you tell the encoding of "Krak�w" just by looking at it?
  • is the character encoding of the response from the api dependant on the code/language or fixed by the api?
  • is character encoding just about how characters appear on screen or does changing the encoding actually change the underlying data?
  • anyone know enough vscode / powershell to suggest a solution?

 

thanks in anticipation.

 

Link to comment
Share on other sites

ginjaninja
8 hours ago, PenkethBoy said:

try utf-16 or unicode

utf-8 has limits

thanks @PenkethBoy i have tried

$apiresult = Invoke-RestMethod -ContentType 'application/json; charset=utf-16' $apiurl
and
$apiresult = Invoke-RestMethod -ContentType 'application/json; charset=unicode' $apiurl

no change

i suspect that i am hopelessly out of my depth on the correct syntax and in particular on the difference between -contenttype switch and -headers switch and which one (if any) affects (the interpretation of?) the response.

Do you have special characters in your library, are you able to get them to show correctly in vs code?

There are articles on the internet which suggest different powershell versions, ise and even encoding of the script file can make a difference.

Link to comment
Share on other sites

ginjaninja
17 hours ago, PenkethBoy said:

try utf-16 or unicode

utf-8 has limits

omg, thats embarrassing....the source data was wrong in the database...at some point emby had fetched the data with the wrong encoding...have since refreshed and everythings ok...

sorry for wasting your time...thanks for help.

Link to comment
Share on other sites

PenkethBoy

yes i have seen this - if it comes in wrong to db at somepoint - then only a refresh will fix it

was going to suggest that next

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