Hello everyone,
I recently encountered an unexpected issue when saving a custom Python script in an ArcGIS Pro toolbox (.atbx). Parts of a formatted string within the code are removed or replaced with spaces upon saving. Specifically, the affected string is: xmlns="urn:Redlines.xsd"
The issue occurs regardless of whether the value is stored in a normal string, a formatted string, or a multiline string.
Issue Details:
After saving the tool inside the toolbox, the string xmlns="urn:Redlines.xsd" is either removed or replaced with spaces. This happens when:
The Python tool is opened in the code editor and saved using the "OK" button.
The problem is reproducible across different toolbox versions, different ArcGIS Pro projects, different users, and different ArcGIS Pro versions (3.3.0 and 3.3.2). However, this issue does not occur within Python toolboxes (.pyt).
Tested Environment:
ArcGIS Pro 3.3.2 (also occurs in 3.3.0)
Multiple different toolbox files (.atbx) tested
The issue is independent of the toolbox version
Expected Behavior:
The original string should remain unchanged and should not be automatically modified upon saving.
Questions:
Is this a known issue?
Is there a way to prevent the automatic removal or replacement of the string?
If this is a bug, is there a known fix or workaround?
My Workaround:
To avoid this issue, I encoded the string in Base64 and then decoded it at runtime:
import base64
# Base64 encoded string to preserve the value
encoded_str = "eG1sbnM9InVybjpSZWRsaW5lcy54c2Qi"
# Decode Base64 back to the original string
decoded_bytes = base64.b64decode(encoded_str)
decoded_str = decoded_bytes.decode('utf-8')
This ensures that the string remains intact when saved in the toolbox.
Has anyone else encountered this issue? If so, do you know why this happens, and are there alternative solutions?
Thanks in advance for any insights!
Best Regards
Daniel
Solved! Go to Solution.
Where is the string being used/assigned?
are you manually putting the string in or defining it somewhere?
Can you confirm that input string has the form
r'xmlns="urn:Redlines.xsd"'
'xmlns="urn:Redlines.xsd"'
'''xmlns="urn:Redlines.xsd"'''
and the string includes xmlns=
Side notes
other encodings are used in various parts of arcgis pro, for example in Calculate Field there is this
ArcGIS applications use UTF-16-LE encoding to read and write .cal files. Other applications (for example, Notepad) can be used to create or modify .cal files as long as the file is written using UTF-16-LE encoding. A file with any other encoding will not load into the code block.
So where the string "is" and what it is part of
Where is the string being used/assigned?
are you manually putting the string in or defining it somewhere?
Can you confirm that input string has the form
r'xmlns="urn:Redlines.xsd"'
'xmlns="urn:Redlines.xsd"'
'''xmlns="urn:Redlines.xsd"'''
and the string includes xmlns=
Side notes
other encodings are used in various parts of arcgis pro, for example in Calculate Field there is this
ArcGIS applications use UTF-16-LE encoding to read and write .cal files. Other applications (for example, Notepad) can be used to create or modify .cal files as long as the file is written using UTF-16-LE encoding. A file with any other encoding will not load into the code block.
So where the string "is" and what it is part of
Thanks for your response!
Yes, I am manually assigning the string to a variable within the script. The issue occurs regardless of how the string is defined, whether as a normal string, a formatted string, or a multiline string. So I can confirm that the input string takes one of the following forms and includes xmlns=:
my_string = r'xmlns="urn:Redlines.xsd"'
my_string = 'xmlns="urn:Redlines.xsd"'
my_string = '''xmlns="urn:Redlines.xsd"'''
To better illustrate the issue, I recorded a GIF where you can see the behavior in a completely new, empty ArcGIS Pro project: after saving the script, the string is removed.
The mention of UTF-16-LE encoding in ArcGIS Pro is very interesting, and after looking into it further, I think this could actually be the root cause of the issue. If ArcGIS Pro enforces UTF-16-LE encoding when saving the toolbox, it might be stripping or altering certain characters in the process.
Based on the observed behavior and the information about ArcGIS Pro using UTF-16-LE encoding for certain files, we strongly suspect that this encoding might also affect .atbx files, leading to the removal or alteration of certain strings. Could this be the case?