How to avoid Stardog over HTTP API encoding errors?

I am using python requests to make HTTP POST API calls against my endpoint:

But getting errors like that:

UnicodeEncodeError: 'latin-1' codec can't encode character '\u2019' in position 577: Body ('’') is not valid Latin-1. Use body.encode('utf-8') if you want to send it encoded in UTF-8.

So if I follow the advice:
description = description.encode('utf-8')

I am getting another error:

500 {"message":"com.complexible.stardog.plan.eval.ExecutionException: Lexical error at line 9, column 537. Encountered: "\n" (10), after : "\'"","code":"000012"}

I get further along when I use this:
description = description.encode("unicode_escape").decode("utf-8")

But getting errors like:

400 {"message":"com.complexible.stardog.plan.eval.ExecutionException: closing brace missing","code":"QE0PE2"}

And it is really annoying that the same insert data works just fine if I copy and paste in Studio or Postman. It fails only when I am making python requests HTTP POST calls.

Here is a sample description:
from Account Manipulation: SSH Authorized Keys, Sub-technique T1098.004 - Enterprise | MITRE ATT&CK®
description = "Adversaries may modify the SSH authorized_keys file to maintain persistence on a victim host. Linux distributions and macOS commonly use key-based authentication to secure the authentication process of SSH sessions for remote management. The authorized_keys file in SSH specifies the SSH keys that can be used for logging into the user account for which the file is configured. This file is usually found in the user's home directory under <user-home>/.ssh/authorized_keys.(Citation: SSH Authorized Keys) Users may edit the system\u2019s SSH config file to modify the directives PubkeyAuthentication and RSAAuthentication to the value \u201cyes\u201d to ensure public key and RSA authentication are enabled. The SSH config file is usually located under /etc/ssh/sshd_config.\n\nAdversaries may modify SSH authorized_keys files directly with scripts or shell commands to add their own adversary-supplied public keys. This ensures that an adversary possessing the corresponding private key may log in as an existing user via SSH.(Citation: Venafi SSH Key Abuse) (Citation: Cybereason Linux Exim Worm)"

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.