Skip to content

Commit 9b984ec

Browse files
[client] Force file read and rabbitmq send to use utf-8 charset
1 parent 0c0d051 commit 9b984ec

6 files changed

+8
-8
lines changed

pycti/api/opencti_api_client.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ def upload_file(self, **kwargs):
629629
}
630630
"""
631631
if data is None:
632-
data = open(file_name, "rb")
632+
data = open(file_name, "rb", encoding="utf-8")
633633
if file_name.endswith(".json"):
634634
mime_type = "application/json"
635635
else:
@@ -664,7 +664,7 @@ def upload_pending_file(self, **kwargs):
664664
}
665665
"""
666666
if data is None:
667-
data = open(file_name, "rb")
667+
data = open(file_name, "rb", encoding="utf-8")
668668
if file_name.endswith(".json"):
669669
mime_type = "application/json"
670670
else:

pycti/connector/opencti_connector_helper.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1057,7 +1057,7 @@ def _send_bundle(self, channel, bundle, **kwargs) -> None:
10571057
routing_key=self.connector_config["push_routing"],
10581058
body=json.dumps(message),
10591059
properties=pika.BasicProperties(
1060-
delivery_mode=2, # make message persistent
1060+
delivery_mode=2, content_encoding="utf-8" # make message persistent
10611061
),
10621062
)
10631063
except (UnroutableError, NackError) as e:

pycti/entities/opencti_external_reference.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ def add_file(self, **kwargs):
235235
}
236236
"""
237237
if data is None:
238-
data = open(file_name, "rb")
238+
data = open(file_name, "rb", encoding="utf-8")
239239
if file_name.endswith(".json"):
240240
mime_type = "application/json"
241241
else:

pycti/entities/opencti_stix_cyber_observable.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ def add_file(self, **kwargs):
488488
}
489489
"""
490490
if data is None:
491-
data = open(file_name, "rb")
491+
data = open(file_name, "rb", encoding="utf-8")
492492
if file_name.endswith(".json"):
493493
mime_type = "application/json"
494494
else:
@@ -1300,7 +1300,7 @@ def upload_artifact(self, **kwargs):
13001300
}
13011301
"""
13021302
if data is None:
1303-
data = open(file_name, "rb")
1303+
data = open(file_name, "rb", encoding="utf-8")
13041304
if file_name.endswith(".json"):
13051305
mime_type = "application/json"
13061306
else:

pycti/entities/opencti_stix_domain_object.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,7 @@ def add_file(self, **kwargs):
815815
}
816816
"""
817817
if data is None:
818-
data = open(file_name, "rb")
818+
data = open(file_name, "rb", encoding="utf-8")
819819
if file_name.endswith(".json"):
820820
mime_type = "application/json"
821821
else:

pycti/utils/opencti_stix2.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def import_bundle_from_file(
182182
if not os.path.isfile(file_path):
183183
API_LOGGER.error("The bundle file does not exists")
184184
return None
185-
with open(os.path.join(file_path)) as file:
185+
with open(os.path.join(file_path), encoding="utf-8") as file:
186186
data = json.load(file)
187187
return self.import_bundle(data, update, types)
188188

0 commit comments

Comments
 (0)