Skip to content

Commit

Permalink
[client] Force file read and rabbitmq send to use utf-8 charset
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-julien committed Jul 5, 2023
1 parent 0c0d051 commit 9b984ec
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions pycti/api/opencti_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ def upload_file(self, **kwargs):
}
"""
if data is None:
data = open(file_name, "rb")
data = open(file_name, "rb", encoding="utf-8")
if file_name.endswith(".json"):
mime_type = "application/json"
else:
Expand Down Expand Up @@ -664,7 +664,7 @@ def upload_pending_file(self, **kwargs):
}
"""
if data is None:
data = open(file_name, "rb")
data = open(file_name, "rb", encoding="utf-8")
if file_name.endswith(".json"):
mime_type = "application/json"
else:
Expand Down
2 changes: 1 addition & 1 deletion pycti/connector/opencti_connector_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,7 @@ def _send_bundle(self, channel, bundle, **kwargs) -> None:
routing_key=self.connector_config["push_routing"],
body=json.dumps(message),
properties=pika.BasicProperties(
delivery_mode=2, # make message persistent
delivery_mode=2, content_encoding="utf-8" # make message persistent
),
)
except (UnroutableError, NackError) as e:
Expand Down
2 changes: 1 addition & 1 deletion pycti/entities/opencti_external_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def add_file(self, **kwargs):
}
"""
if data is None:
data = open(file_name, "rb")
data = open(file_name, "rb", encoding="utf-8")
if file_name.endswith(".json"):
mime_type = "application/json"
else:
Expand Down
4 changes: 2 additions & 2 deletions pycti/entities/opencti_stix_cyber_observable.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ def add_file(self, **kwargs):
}
"""
if data is None:
data = open(file_name, "rb")
data = open(file_name, "rb", encoding="utf-8")
if file_name.endswith(".json"):
mime_type = "application/json"
else:
Expand Down Expand Up @@ -1300,7 +1300,7 @@ def upload_artifact(self, **kwargs):
}
"""
if data is None:
data = open(file_name, "rb")
data = open(file_name, "rb", encoding="utf-8")
if file_name.endswith(".json"):
mime_type = "application/json"
else:
Expand Down
2 changes: 1 addition & 1 deletion pycti/entities/opencti_stix_domain_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ def add_file(self, **kwargs):
}
"""
if data is None:
data = open(file_name, "rb")
data = open(file_name, "rb", encoding="utf-8")
if file_name.endswith(".json"):
mime_type = "application/json"
else:
Expand Down
2 changes: 1 addition & 1 deletion pycti/utils/opencti_stix2.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def import_bundle_from_file(
if not os.path.isfile(file_path):
API_LOGGER.error("The bundle file does not exists")
return None
with open(os.path.join(file_path)) as file:
with open(os.path.join(file_path), encoding="utf-8") as file:
data = json.load(file)
return self.import_bundle(data, update, types)

Expand Down

0 comments on commit 9b984ec

Please sign in to comment.