'utf-8' codec can't decode byte 0x82 in position 24: invalid start byte

456 views
Skip to first unread message

herve naga

unread,
Mar 8, 2024, 10:54:06 AM3/8/24
to rundeck-discuss
Hello everyone

i have tried to use WinRMPyton (With Python3) but when i execute a remote script Batch on my remote windows server I have the error message: [ERROR ] 'utf-8' codec can't decode byte 0x82 in position 24: invalid start byte (winrm-exec.py:362)[root]

In this script i'am using the special character '&' and i'am thinking that it the problem

I use Rundeck 5.1
For information, on the oldest version 4.7 i'm using ovethere-winrm and my script working

If I have understand well 'overthere-winrm' will be abdonned

Do you have an idea for solving this problem ?

thanks in advance

rac...@rundeck.com

unread,
Mar 8, 2024, 10:56:28 AM3/8/24
to rundeck-discuss
Hi!

You're facing this issue, could you add your use case there? Please add a job definition example.

Regards!

rac...@rundeck.com

unread,
Mar 8, 2024, 11:27:07 AM3/8/24
to rundeck-discuss

BTW, I tested using the following job definition example:

- defaultTab: nodes description: '' executionEnabled: true id: 58f26822-49cd-402b-ac7f-8e37772dc68f loglevel: INFO name: HelloWorld nodeFilterEditable: false nodefilters: dispatch: excludePrecedence: true keepgoing: false rankOrder: ascending successOnEmptyNodeFilter: false threadcount: '1' filter: 'name: windows ' nodesSelectedByDefault: true plugins: ExecutionLifecycle: {} scheduleEnabled: true sequence: commands: - exec: C:\Users\user\Downloads\example.bat keepgoing: false strategy: node-first uuid: 58f26822-49cd-402b-ac7f-8e37772dc68f

This calls the following basic Windows batch script:

echo whoami & dir

But it works great for me. Could you provide a reproducible example? Regards!

herve naga

unread,
Mar 11, 2024, 8:41:44 AM3/11/24
to rundeck-discuss
Hello

thanks for your answers


My environment
------------------------------------------------
- Ubuntu 22.04.4 LTS (Jammy Jellyfish)
- Rundeck 5.1.1
- PostgreSQL 16.2
- Python : 3.11.8
- pywinrm : 0.4.3




Below my job definition:
------------------------------------------------

[ {
  "defaultTab" : "nodes",
  "description" : "",
  "executionEnabled" : true,
  "group" : "TEST",
  "id" : "0da23d47-774c-4cc3-9694-ce926397b6e6",
  "loglevel" : "INFO",
  "name" : "F_CM_EDIJ003",
  "nodeFilterEditable" : false,
  "nodefilters" : {
    "dispatch" : {
      "excludePrecedence" : true,
      "keepgoing" : false,
      "rankOrder" : "ascending",
      "successOnEmptyNodeFilter" : false,
      "threadcount" : "1"
    },
    "filter" : "pwordo001"
  },
  "nodesSelectedByDefault" : true,
  "plugins" : {
    "ExecutionLifecycle" : { }
  },
  "scheduleEnabled" : true,
  "sequence" : {
    "commands" : [ {
      "exec" : "C:\\Exploit\\copy_testhna.cmd"
    } ],
    "keepgoing" : false,
    "strategy" : "node-first"
  },
  "uuid" : "0da23d47-774c-4cc3-9694-ce926397b6e6"
} ]



Below my script BATCH on my remote server
-------------------------------------------------------------------------

INFORMATION: My password contains special characters including --> &
I know it's not clean but for the moment i would only like triggering the script from Rundeck before rewrite it later


# Script : copy_testhna.cmd #
net use Y: \\MyServer\MyDirectory /user:domain\MyUser %password%
echo Aucun fichier a copier
net use Y: /delete


I execute the commands echo whoami & dir  it's working.


The result log of my Job

[ERROR  ]  Execution finished with the following error (winrm-exec.py:378)[root]
[ERROR  ]  L'erreur systme 86 s'est produite.
Le mot de passe rseau spcifi est incorrect.
La connexion rseau est introuvable.
Vous obtiendrez une aide supplmentaire en entrant NET HELPMSG 2250.


I tried on my password to use % or \ or ^  to fix/freeze it but it's not working

Thanks yet for your Help



Best Regards

herve naga

unread,
Mar 11, 2024, 8:58:06 AM3/11/24
to rundeck-discuss
sorry,
My remote Windows server : 2012 R2

rac...@rundeck.com

unread,
Mar 11, 2024, 11:49:38 AM3/11/24
to rundeck-discuss

I was checking the code. The plugin validates the charset from Python and then tries to force it to UTF-8.

Some approaches here. Please test from a non-prod server/instance.

  1. Can you launch that script from the script step instead of the command step? (e.g. using an inline-script, just for testing).
  2. Try forcing the Rundeck instance Python default charset to UTF-8.
  3. Also, try to force the default Rundeck Instance charset by adding the -Dfile.encoding=UTF-8 param to launch Rundeck like this.

Regards.

herve naga

unread,
Mar 12, 2024, 6:18:19 AM3/12/24
to rundeck-discuss
Hello
Thanks yet

I tested your solutions but the problem persist but may be that i make a mistake


(1) When i use then inline script i have the following message error
  [ERROR ] La syntaxe du nom de fichier, de répertoire ou de volume est incorrecte.

(2) I forced the default charset python to UTF-8
(2.1) via the 'remote command' : set PYTHONIOENCODING=utf-8 & C:\Exploit\copy_testhna.cmd  
           (2.2)  Directly in the script copy_testhna.cmd in the first line

(3) I added the  parameter -Dfile.encoding=UTF-8 for the variable RDECK_JVM 


Do you want any more informations ?

Thanks.

Regards

rac...@rundeck.com

unread,
Mar 12, 2024, 9:01:39 AM3/12/24
to rundeck-discuss
I see, what about the "Script file or URL" step? Make sure to define the "Invocation String" (cmd.exe) and "File Extension" (.bat).

So, could you determine what is the default Windows charset? Probably only understands a specific charset like iso8859-1.

Greetings.

herve naga

unread,
Mar 12, 2024, 11:29:08 AM3/12/24
to rundeck-discuss
Thanks
if i test with script file my Job is blocked in running mode
however the temporary script is create on remote windows to c:\windows\temp

For character set of our remote windows server :

IsSingleByte      : True
BodyName          : us-ascii
EncodingName      : US-ASCII
HeaderName        : us-ascii
WebName           : us-ascii
WindowsCodePage   : 1252
IsBrowserDisplay  : False
IsBrowserSave     : False
IsMailNewsDisplay : True
IsMailNewsSave    : True
EncoderFallback   : System.Text.EncoderReplacementFallback
DecoderFallback   : System.Text.DecoderReplacementFallback
IsReadOnly        : True
CodePage          : 20127

thank you for all your help

rac...@rundeck.com

unread,
Mar 13, 2024, 9:08:40 AM3/13/24
to rundeck-discuss
Hi,

After some research, you can try setting this in your Windows model source definition (check the " output-charset" attribute). Also this.

Anyway, the bat scripts are ANSI encoded by default. So, testing PowerShell could be a great way to isolate the root cause.

Regards.

rac...@rundeck.com

unread,
Mar 13, 2024, 9:22:01 AM3/13/24
to rundeck-discuss
Please test using your current server charset and utf8 (with all config elements together: the boot flag with the node attributes).

Greetings.

herve naga

unread,
Mar 13, 2024, 1:09:25 PM3/13/24
to rundeck-discuss
Thanks yet
despite all config elements + flag boot.  It'ts not working

for the tests my script is simple :

net use Y: \\MyServer.MyDomain\MyShare /user:Mydomain\MyAccount "xxxxxxxxxxxxxxxxxxxxx&t!"
net use Y: /delete

as you said i rewrite the script in powershell like this and it's working:

$shareletter="Y:"
$shareuser="MyDomain\MyAccount"
$password='xxxxxxxxxxxxxxxxxxxx&t!'
$sharepath='\\MyServer.MyDomain\MyShare'

try {
      New-SmbMapping -LocalPath $shareletter -RemotePath $sharepath -Username $shareuser -Password $password
    } catch {
     Write-Host "Impossible de mapper X: vers $sharepath"
}

All config elements and flag boot are always present


Thanks you for taking time for myself
Reply all
Reply to author
Forward
0 new messages