BatmanAMA / powerbox

Netbox powershell module
MIT License
47 stars 18 forks source link

Problem with non english Characters when getting Objects #43

Open RudolfAchter opened 4 years ago

RudolfAchter commented 4 years ago

For this one i have no fix for now.

There are also issues whent getting Objects with german umlauts

image

thefreakquency commented 3 years ago

I have the same issue when trying to update with accents Using: foreach ($site in $sites) { $values= [PScustomObject]@{ name = $site.site_EngNumber status = $site.site_status region = $site.site_region tenant = $site.site_tenant facility = $site.site_name description = $site.site_description physical_address = $site.site_address latitude = $site.site_latitude longitude = $site.site_longitude comments = $site.site_comments tags = $site.site_tags } $updates = $values | remove-Null write-host "[INFO] Atempting an update with those values:" $updates write-host "[INFO] Result: " if ($allsites.name -contains $site.site_engNumber) { $site_data = Get-nbSite -Query @{name=$site.site_EngNumber} Set-nbSite -id $site_data.id -Object $updates -Patch } else { write-host "[WARNING] Engineering site number not found in Netbox." -background red write-host "----------------------------------------------------------------------" } }

I get the following output: [INFO] Atempting an update with those values: name : R#### status : active facility : R#### Édifice (redacted) physical_address : redacted latitude : ##.##### longitude : -##.##### tags : {3}

[INFO] Result:

Invoke-nbApi : {"detail":"JSON parse error - 'utf-8' codec can't decode byte 0xc9 in position 234: invalid continuation byte"}
At C:\Users\redacted\Documents\WindowsPowerShell\Modules\powerbox\2.3.5\Public\Set-nbObject.ps1:127 char:16
+ ...      return Invoke-nbApi -Resource $Resource/$id -HttpVerb Patch -Bod ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-nbApi], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Invoke-nbApi
Invoke-nbApi : {"detail":"JSON parse error - 'utf-8' codec can't decode byte 0xc9 in position 234: invalid continuation byte"}
At C:\Users\redacted\Documents\WindowsPowerShell\Modules\powerbox\2.3.5\Public\Set-nbObject.ps1:129 char:12
+     return Invoke-nbApi -Resource $Resource/$id -HttpVerb Put -Body ( ...
+            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-nbApi], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Invoke-nbApi
thefreakquency commented 3 years ago

I was able to fix updates by changing line #121 of Invoke-nb-Api.ps1 from ContentType = 'application/json' to ContentType = 'application/json; charset=utf-8' That fixes the uploads and accents are well represented when looking at the WebUI.

That being said, I was not able to find the encoding for the gets. I still get gibberish characters when loading information that contains UTF-8 caracters... :| Scheiße!

thefreakquency commented 3 years ago

@RudolfAchter , I was able to get proper UTF8 characters in console using PowerShell 7.0.4

Previously, I was using powershell 5.1.19041.610 and it seems that 5.1 has some issues rendering proper character set in terminal. a Workaround would have been to output to file and reload to terminal forcing UTF-8 but it seems like a stretch to me...

RudolfAchter commented 3 years ago

@RudolfAchter , I was able to get proper UTF8 characters in console using PowerShell 7.0.4

Previously, I was using powershell 5.1.19041.610 and it seems that 5.1 has some issues rendering proper character set in terminal. a Workaround would have been to output to file and reload to terminal forcing UTF-8 but it seems like a stretch to me...

@thefreakquency . I almost forgot about this issue :-) . I recently had no time to work with my Netbox / Powerbox Instance. But Thank you for your suggestions to fix this. I will try it in my installation