SharePoint GetFileByServerRelativeUrl problems with comment text

LaFetra, Ross 1 Reputation point
2022-03-08T02:35:56.053+00:00

I am using Python's SharePlum, and am having problems with checking in a file with comments. I can successfully checkin a file with comments, but there appears to be restrictions on the comments that are not present when using SharePoint through a browser. I've traced this through Python to the url used, and all seems well, but something on the SharePoint side is rejecting it. I cannot find much documentation about what can appear in the comment text, I have found something that says the comment text is limited to 1023 characters, but nothing about restricted characters in comments, and the browser interface allows those characters. Sharepoint version is Office365 I think.

The python code
folder.check_in('HelloWorld.txt','leg<al')
generates the url
https://mycompany.sharepoint.com/sites/mysite/_api/web/GetFileByServerRelativeUrl('/sites/mysite/Shared%20Documents/myfolder/HelloWorld.txt')/CheckIn(comment='leg<al',checkintype=0)

and fails with the message:

Traceback (most recent call last):
File "C:\Users\myuser\Anaconda3\lib\site-packages\shareplum\request_helper.py", line 18, in post
response.raise_for_status()
File "C:\Users\myuser\Anaconda3\lib\site-packages\requests\models.py", line 953, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://mycompany.sharepoint.com/sites/mysite/\_api/web/GetFileByServerRelativeUrl('/sites/mysite/Shared%20Documents/myfolder/HelloWorld.txt')/CheckIn(comment='leg%3Cal',checkintype=0)

The python code (just missing the '<' in the string)
folder.check_in('HelloWorld.txt','legal')
generates the url
https://mycompany.sharepoint.com/sites/mysite/\_api/web/GetFileByServerRelativeUrl('/sites/mysite/Shared%20Documents/myfolder/HelloWorld.txt')/CheckIn(comment='legal',checkintype=0)

and works.

Again, I have no problems with the '<' in the comments when I check it in the browser. I can reproduce this on 2 of 2 machines I've tried. There are two characters I am primarily interested in: > and newline. Any hints on how to do this?

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,300 questions
0 comments No comments
{count} votes