We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[AbuseIPdb] Crash on listing  "Korea (Republic of)" entity
## Description

The AbuseIPDB enrichment connector stops gathering data as soon as there is an entity of "Korea (Republic of)" is found. 

## Actual Output

Example listing:
```
connector-abuseipdb_1                    | 2021-05-20T13:07:59.843767030Z INFO:root:Listing Stix-Domain-Objects with filters [{"key": "name", "values": ["Korea (Republic of)"]}].
connector-abuseipdb_1                    | 2021-05-20T13:07:59.859596474Z INFO:root:Listing Stix-Domain-Objects with filters [{"key": "aliases", "values": ["Korea (Republic of)"]}].
connector-abuseipdb_1                    | 2021-05-20T13:07:59.959406389Z ERROR:root:Error in message processing, reporting error to API
connector-abuseipdb_1                    | 2021-05-20T13:07:59.959533538Z Traceback (most recent call last):
connector-abuseipdb_1                    | 2021-05-20T13:07:59.959542290Z   File "/usr/local/lib/python3.9/site-packages/pycti/connector/opencti_connector_helper.py", line 145, in _data_handler
connector-abuseipdb_1                    | 2021-05-20T13:07:59.959548366Z     message = self.callback(json_data["event"])
connector-abuseipdb_1                    | 2021-05-20T13:07:59.959553788Z   File "/opt/opencti-connector-abuseipdb/abuseipdb.py", line 108, in _process_message
connector-abuseipdb_1                    | 2021-05-20T13:07:59.959559549Z     toId=country["id"],
connector-abuseipdb_1                    | 2021-05-20T13:07:59.959564881Z TypeError: 'NoneType' object is not subscriptable

``` 
## Additional information

The error above has been using IP address 143.198.132.45

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `abuseipdb/src/abuseipdb.py`
Content:
```
1 import yaml
2 import os
3 import requests
4 
5 from pycti import OpenCTIConnectorHelper, get_config_variable
6 
7 
8 class AbuseIPDBConnector:
9     def __init__(self):
10         # Instantiate the connector helper from config
11         config_file_path = os.path.dirname(os.path.abspath(__file__)) + "/config.yml"
12         config = (
13             yaml.load(open(config_file_path), Loader=yaml.FullLoader)
14             if os.path.isfile(config_file_path)
15             else {}
16         )
17         self.helper = OpenCTIConnectorHelper(config)
18         self.api_key = get_config_variable(
19             "ABUSEIPDB_API_KEY", ["abuseipdb", "api_key"], config
20         )
21         self.max_tlp = get_config_variable(
22             "ABUSEIPDB_MAX_TLP", ["abuseipdb", "max_tlp"], config
23         )
24         self.whitelist_label = self.helper.api.label.create(
25             value="whitelist", color="#4caf50"
26         )
27 
28     @staticmethod
29     def extract_abuse_ipdb_category(category_number):
30         # Reference: https://www.abuseipdb.com/categories
31         mapping = {
32             "3": "Fraud Orders",
33             "4": "DDOS Attack",
34             "5": "FTP Brute-Force",
35             "6": "Ping of Death",
36             "7": "Phishing",
37             "8": "Fraud VOIP",
38             "9": "Open Proxy",
39             "10": "Web Spam",
40             "11": "Email Spam",
41             "12": "Blog Spam",
42             "13": "VPN IP",
43             "14": "Port Scan",
44             "15": "Hacking",
45             "16": "SQL Injection",
46             "17": "Spoofing",
47             "18": "Brute Force",
48             "19": "Bad Web Bot",
49             "20": "Exploited Host",
50             "21": "Web App Attack",
51             "22": "SSH",
52             "23": "IoT Targeted",
53         }
54         return mapping.get(str(category_number), "unknown category")
55 
56     def _process_message(self, data):
57         entity_id = data["entity_id"]
58         observable = self.helper.api.stix_cyber_observable.read(id=entity_id)
59         # Extract TLP
60         tlp = "TLP:WHITE"
61         for marking_definition in observable["objectMarking"]:
62             if marking_definition["definition_type"] == "TLP":
63                 tlp = marking_definition["definition"]
64 
65         if not OpenCTIConnectorHelper.check_max_tlp(tlp, self.max_tlp):
66             raise ValueError(
67                 "Do not send any data, TLP of the observable is greater than MAX TLP"
68             )
69         # Extract IP from entity data
70         observable_id = observable["standard_id"]
71         observable_value = observable["value"]
72         url = "https://api.abuseipdb.com/api/v2/check"
73         headers = {
74             "Accept": "application/json",
75             "Content-Type": "application/x-www-form-urlencoded",
76             "Key": "%s" % self.api_key,
77         }
78         params = {"maxAgeInDays": 365, "verbose": "True", "ipAddress": observable_value}
79         r = requests.get(url, headers=headers, params=params)
80         r.raise_for_status()
81         data = r.json()
82         data = data["data"]
83         self.helper.api.stix_cyber_observable.update_field(
84             id=observable_id,
85             key="x_opencti_score",
86             value=str(data["abuseConfidenceScore"]),
87         )
88         if data["isWhitelisted"]:
89             external_reference = self.helper.api.external_reference.create(
90                 source_name="AbuseIPDB (whitelist)",
91                 url="https://www.abuseipdb.com/check/" + observable_value,
92                 description="This IP address is from within our whitelist.",
93             )
94             self.helper.api.stix_cyber_observable.add_external_reference(
95                 id=observable_id, external_reference_id=external_reference["id"]
96             )
97             self.helper.api.stix_cyber_observable.add_label(
98                 id=observable_id, label_id=self.whitelist_label["id"]
99             )
100             return "IP found in AbuseIPDB WHITELIST."
101         if len(data["reports"]) > 0:
102             for report in data["reports"]:
103                 country = self.helper.api.stix_domain_object.get_by_stix_id_or_name(
104                     name=report["reporterCountryName"]
105                 )
106                 self.helper.api.stix_sighting_relationship.create(
107                     fromId=observable_id,
108                     toId=country["id"],
109                     count=1,
110                     first_seen=report["reportedAt"],
111                     last_seen=report["reportedAt"],
112                 )
113                 for category in report["categories"]:
114                     category_text = self.extract_abuse_ipdb_category(category)
115                     label = self.helper.api.label.create(value=category_text)
116                     self.helper.api.stix_cyber_observable.add_label(
117                         id=observable_id, label_id=label["id"]
118                     )
119             return "IP found in AbuseIPDB with reports, knowledge attached."
120 
121     # Start the main loop
122     def start(self):
123         self.helper.listen(self._process_message)
124 
125 
126 if __name__ == "__main__":
127     abuseIPDBInstance = AbuseIPDBConnector()
128     abuseIPDBInstance.start()
129
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/abuseipdb/src/abuseipdb.py b/abuseipdb/src/abuseipdb.py
--- a/abuseipdb/src/abuseipdb.py
+++ b/abuseipdb/src/abuseipdb.py
@@ -100,16 +100,27 @@
             return "IP found in AbuseIPDB WHITELIST."
         if len(data["reports"]) > 0:
             for report in data["reports"]:
-                country = self.helper.api.stix_domain_object.get_by_stix_id_or_name(
-                    name=report["reporterCountryName"]
-                )
-                self.helper.api.stix_sighting_relationship.create(
-                    fromId=observable_id,
-                    toId=country["id"],
-                    count=1,
-                    first_seen=report["reportedAt"],
-                    last_seen=report["reportedAt"],
+                country = self.helper.api.location.read(
+                    filters=[
+                        {
+                            "key": "x_opencti_aliases",
+                            "values": [report["reporterCountryCode"]],
+                        }
+                    ],
+                    getAll=True,
                 )
+                if country is None:
+                    self.helper.log_warning(
+                        f"No country found with Alpha 2 code {report['reporterCountryCode']}"
+                    )
+                else:
+                    self.helper.api.stix_sighting_relationship.create(
+                        fromId=observable_id,
+                        toId=country["id"],
+                        count=1,
+                        first_seen=report["reportedAt"],
+                        last_seen=report["reportedAt"],
+                    )
                 for category in report["categories"]:
                     category_text = self.extract_abuse_ipdb_category(category)
                     label = self.helper.api.label.create(value=category_text)

{"golden_diff": "diff --git a/abuseipdb/src/abuseipdb.py b/abuseipdb/src/abuseipdb.py\n--- a/abuseipdb/src/abuseipdb.py\n+++ b/abuseipdb/src/abuseipdb.py\n@@ -100,16 +100,27 @@\n             return \"IP found in AbuseIPDB WHITELIST.\"\n         if len(data[\"reports\"]) > 0:\n             for report in data[\"reports\"]:\n-                country = self.helper.api.stix_domain_object.get_by_stix_id_or_name(\n-                    name=report[\"reporterCountryName\"]\n-                )\n-                self.helper.api.stix_sighting_relationship.create(\n-                    fromId=observable_id,\n-                    toId=country[\"id\"],\n-                    count=1,\n-                    first_seen=report[\"reportedAt\"],\n-                    last_seen=report[\"reportedAt\"],\n+                country = self.helper.api.location.read(\n+                    filters=[\n+                        {\n+                            \"key\": \"x_opencti_aliases\",\n+                            \"values\": [report[\"reporterCountryCode\"]],\n+                        }\n+                    ],\n+                    getAll=True,\n                 )\n+                if country is None:\n+                    self.helper.log_warning(\n+                        f\"No country found with Alpha 2 code {report['reporterCountryCode']}\"\n+                    )\n+                else:\n+                    self.helper.api.stix_sighting_relationship.create(\n+                        fromId=observable_id,\n+                        toId=country[\"id\"],\n+                        count=1,\n+                        first_seen=report[\"reportedAt\"],\n+                        last_seen=report[\"reportedAt\"],\n+                    )\n                 for category in report[\"categories\"]:\n                     category_text = self.extract_abuse_ipdb_category(category)\n                     label = self.helper.api.label.create(value=category_text)\n", "issue": "[AbuseIPdb] Crash on listing  \"Korea (Republic of)\" entity\n## Description\r\n\r\nThe AbuseIPDB enrichment connector stops gathering data as soon as there is an entity of \"Korea (Republic of)\" is found. \r\n\r\n## Actual Output\r\n\r\nExample listing:\r\n```\r\nconnector-abuseipdb_1                    | 2021-05-20T13:07:59.843767030Z INFO:root:Listing Stix-Domain-Objects with filters [{\"key\": \"name\", \"values\": [\"Korea (Republic of)\"]}].\r\nconnector-abuseipdb_1                    | 2021-05-20T13:07:59.859596474Z INFO:root:Listing Stix-Domain-Objects with filters [{\"key\": \"aliases\", \"values\": [\"Korea (Republic of)\"]}].\r\nconnector-abuseipdb_1                    | 2021-05-20T13:07:59.959406389Z ERROR:root:Error in message processing, reporting error to API\r\nconnector-abuseipdb_1                    | 2021-05-20T13:07:59.959533538Z Traceback (most recent call last):\r\nconnector-abuseipdb_1                    | 2021-05-20T13:07:59.959542290Z   File \"/usr/local/lib/python3.9/site-packages/pycti/connector/opencti_connector_helper.py\", line 145, in _data_handler\r\nconnector-abuseipdb_1                    | 2021-05-20T13:07:59.959548366Z     message = self.callback(json_data[\"event\"])\r\nconnector-abuseipdb_1                    | 2021-05-20T13:07:59.959553788Z   File \"/opt/opencti-connector-abuseipdb/abuseipdb.py\", line 108, in _process_message\r\nconnector-abuseipdb_1                    | 2021-05-20T13:07:59.959559549Z     toId=country[\"id\"],\r\nconnector-abuseipdb_1                    | 2021-05-20T13:07:59.959564881Z TypeError: 'NoneType' object is not subscriptable\r\n\r\n``` \r\n## Additional information\r\n\r\nThe error above has been using IP address 143.198.132.45\n", "before_files": [{"content": "import yaml\nimport os\nimport requests\n\nfrom pycti import OpenCTIConnectorHelper, get_config_variable\n\n\nclass AbuseIPDBConnector:\n    def __init__(self):\n        # Instantiate the connector helper from config\n        config_file_path = os.path.dirname(os.path.abspath(__file__)) + \"/config.yml\"\n        config = (\n            yaml.load(open(config_file_path), Loader=yaml.FullLoader)\n            if os.path.isfile(config_file_path)\n            else {}\n        )\n        self.helper = OpenCTIConnectorHelper(config)\n        self.api_key = get_config_variable(\n            \"ABUSEIPDB_API_KEY\", [\"abuseipdb\", \"api_key\"], config\n        )\n        self.max_tlp = get_config_variable(\n            \"ABUSEIPDB_MAX_TLP\", [\"abuseipdb\", \"max_tlp\"], config\n        )\n        self.whitelist_label = self.helper.api.label.create(\n            value=\"whitelist\", color=\"#4caf50\"\n        )\n\n    @staticmethod\n    def extract_abuse_ipdb_category(category_number):\n        # Reference: https://www.abuseipdb.com/categories\n        mapping = {\n            \"3\": \"Fraud Orders\",\n            \"4\": \"DDOS Attack\",\n            \"5\": \"FTP Brute-Force\",\n            \"6\": \"Ping of Death\",\n            \"7\": \"Phishing\",\n            \"8\": \"Fraud VOIP\",\n            \"9\": \"Open Proxy\",\n            \"10\": \"Web Spam\",\n            \"11\": \"Email Spam\",\n            \"12\": \"Blog Spam\",\n            \"13\": \"VPN IP\",\n            \"14\": \"Port Scan\",\n            \"15\": \"Hacking\",\n            \"16\": \"SQL Injection\",\n            \"17\": \"Spoofing\",\n            \"18\": \"Brute Force\",\n            \"19\": \"Bad Web Bot\",\n            \"20\": \"Exploited Host\",\n            \"21\": \"Web App Attack\",\n            \"22\": \"SSH\",\n            \"23\": \"IoT Targeted\",\n        }\n        return mapping.get(str(category_number), \"unknown category\")\n\n    def _process_message(self, data):\n        entity_id = data[\"entity_id\"]\n        observable = self.helper.api.stix_cyber_observable.read(id=entity_id)\n        # Extract TLP\n        tlp = \"TLP:WHITE\"\n        for marking_definition in observable[\"objectMarking\"]:\n            if marking_definition[\"definition_type\"] == \"TLP\":\n                tlp = marking_definition[\"definition\"]\n\n        if not OpenCTIConnectorHelper.check_max_tlp(tlp, self.max_tlp):\n            raise ValueError(\n                \"Do not send any data, TLP of the observable is greater than MAX TLP\"\n            )\n        # Extract IP from entity data\n        observable_id = observable[\"standard_id\"]\n        observable_value = observable[\"value\"]\n        url = \"https://api.abuseipdb.com/api/v2/check\"\n        headers = {\n            \"Accept\": \"application/json\",\n            \"Content-Type\": \"application/x-www-form-urlencoded\",\n            \"Key\": \"%s\" % self.api_key,\n        }\n        params = {\"maxAgeInDays\": 365, \"verbose\": \"True\", \"ipAddress\": observable_value}\n        r = requests.get(url, headers=headers, params=params)\n        r.raise_for_status()\n        data = r.json()\n        data = data[\"data\"]\n        self.helper.api.stix_cyber_observable.update_field(\n            id=observable_id,\n            key=\"x_opencti_score\",\n            value=str(data[\"abuseConfidenceScore\"]),\n        )\n        if data[\"isWhitelisted\"]:\n            external_reference = self.helper.api.external_reference.create(\n                source_name=\"AbuseIPDB (whitelist)\",\n                url=\"https://www.abuseipdb.com/check/\" + observable_value,\n                description=\"This IP address is from within our whitelist.\",\n            )\n            self.helper.api.stix_cyber_observable.add_external_reference(\n                id=observable_id, external_reference_id=external_reference[\"id\"]\n            )\n            self.helper.api.stix_cyber_observable.add_label(\n                id=observable_id, label_id=self.whitelist_label[\"id\"]\n            )\n            return \"IP found in AbuseIPDB WHITELIST.\"\n        if len(data[\"reports\"]) > 0:\n            for report in data[\"reports\"]:\n                country = self.helper.api.stix_domain_object.get_by_stix_id_or_name(\n                    name=report[\"reporterCountryName\"]\n                )\n                self.helper.api.stix_sighting_relationship.create(\n                    fromId=observable_id,\n                    toId=country[\"id\"],\n                    count=1,\n                    first_seen=report[\"reportedAt\"],\n                    last_seen=report[\"reportedAt\"],\n                )\n                for category in report[\"categories\"]:\n                    category_text = self.extract_abuse_ipdb_category(category)\n                    label = self.helper.api.label.create(value=category_text)\n                    self.helper.api.stix_cyber_observable.add_label(\n                        id=observable_id, label_id=label[\"id\"]\n                    )\n            return \"IP found in AbuseIPDB with reports, knowledge attached.\"\n\n    # Start the main loop\n    def start(self):\n        self.helper.listen(self._process_message)\n\n\nif __name__ == \"__main__\":\n    abuseIPDBInstance = AbuseIPDBConnector()\n    abuseIPDBInstance.start()\n", "path": "abuseipdb/src/abuseipdb.py"}], "after_files": [{"content": "import yaml\nimport os\nimport requests\n\nfrom pycti import OpenCTIConnectorHelper, get_config_variable\n\n\nclass AbuseIPDBConnector:\n    def __init__(self):\n        # Instantiate the connector helper from config\n        config_file_path = os.path.dirname(os.path.abspath(__file__)) + \"/config.yml\"\n        config = (\n            yaml.load(open(config_file_path), Loader=yaml.FullLoader)\n            if os.path.isfile(config_file_path)\n            else {}\n        )\n        self.helper = OpenCTIConnectorHelper(config)\n        self.api_key = get_config_variable(\n            \"ABUSEIPDB_API_KEY\", [\"abuseipdb\", \"api_key\"], config\n        )\n        self.max_tlp = get_config_variable(\n            \"ABUSEIPDB_MAX_TLP\", [\"abuseipdb\", \"max_tlp\"], config\n        )\n        self.whitelist_label = self.helper.api.label.create(\n            value=\"whitelist\", color=\"#4caf50\"\n        )\n\n    @staticmethod\n    def extract_abuse_ipdb_category(category_number):\n        # Reference: https://www.abuseipdb.com/categories\n        mapping = {\n            \"3\": \"Fraud Orders\",\n            \"4\": \"DDOS Attack\",\n            \"5\": \"FTP Brute-Force\",\n            \"6\": \"Ping of Death\",\n            \"7\": \"Phishing\",\n            \"8\": \"Fraud VOIP\",\n            \"9\": \"Open Proxy\",\n            \"10\": \"Web Spam\",\n            \"11\": \"Email Spam\",\n            \"12\": \"Blog Spam\",\n            \"13\": \"VPN IP\",\n            \"14\": \"Port Scan\",\n            \"15\": \"Hacking\",\n            \"16\": \"SQL Injection\",\n            \"17\": \"Spoofing\",\n            \"18\": \"Brute Force\",\n            \"19\": \"Bad Web Bot\",\n            \"20\": \"Exploited Host\",\n            \"21\": \"Web App Attack\",\n            \"22\": \"SSH\",\n            \"23\": \"IoT Targeted\",\n        }\n        return mapping.get(str(category_number), \"unknown category\")\n\n    def _process_message(self, data):\n        entity_id = data[\"entity_id\"]\n        observable = self.helper.api.stix_cyber_observable.read(id=entity_id)\n        # Extract TLP\n        tlp = \"TLP:WHITE\"\n        for marking_definition in observable[\"objectMarking\"]:\n            if marking_definition[\"definition_type\"] == \"TLP\":\n                tlp = marking_definition[\"definition\"]\n\n        if not OpenCTIConnectorHelper.check_max_tlp(tlp, self.max_tlp):\n            raise ValueError(\n                \"Do not send any data, TLP of the observable is greater than MAX TLP\"\n            )\n        # Extract IP from entity data\n        observable_id = observable[\"standard_id\"]\n        observable_value = observable[\"value\"]\n        url = \"https://api.abuseipdb.com/api/v2/check\"\n        headers = {\n            \"Accept\": \"application/json\",\n            \"Content-Type\": \"application/x-www-form-urlencoded\",\n            \"Key\": \"%s\" % self.api_key,\n        }\n        params = {\"maxAgeInDays\": 365, \"verbose\": \"True\", \"ipAddress\": observable_value}\n        r = requests.get(url, headers=headers, params=params)\n        r.raise_for_status()\n        data = r.json()\n        data = data[\"data\"]\n        self.helper.api.stix_cyber_observable.update_field(\n            id=observable_id,\n            key=\"x_opencti_score\",\n            value=str(data[\"abuseConfidenceScore\"]),\n        )\n        if data[\"isWhitelisted\"]:\n            external_reference = self.helper.api.external_reference.create(\n                source_name=\"AbuseIPDB (whitelist)\",\n                url=\"https://www.abuseipdb.com/check/\" + observable_value,\n                description=\"This IP address is from within our whitelist.\",\n            )\n            self.helper.api.stix_cyber_observable.add_external_reference(\n                id=observable_id, external_reference_id=external_reference[\"id\"]\n            )\n            self.helper.api.stix_cyber_observable.add_label(\n                id=observable_id, label_id=self.whitelist_label[\"id\"]\n            )\n            return \"IP found in AbuseIPDB WHITELIST.\"\n        if len(data[\"reports\"]) > 0:\n            for report in data[\"reports\"]:\n                country = self.helper.api.location.read(\n                    filters=[\n                        {\n                            \"key\": \"x_opencti_aliases\",\n                            \"values\": [report[\"reporterCountryCode\"]],\n                        }\n                    ],\n                    getAll=True,\n                )\n                if country is None:\n                    self.helper.log_warning(\n                        f\"No country found with Alpha 2 code {report['reporterCountryCode']}\"\n                    )\n                else:\n                    self.helper.api.stix_sighting_relationship.create(\n                        fromId=observable_id,\n                        toId=country[\"id\"],\n                        count=1,\n                        first_seen=report[\"reportedAt\"],\n                        last_seen=report[\"reportedAt\"],\n                    )\n                for category in report[\"categories\"]:\n                    category_text = self.extract_abuse_ipdb_category(category)\n                    label = self.helper.api.label.create(value=category_text)\n                    self.helper.api.stix_cyber_observable.add_label(\n                        id=observable_id, label_id=label[\"id\"]\n                    )\n            return \"IP found in AbuseIPDB with reports, knowledge attached.\"\n\n    # Start the main loop\n    def start(self):\n        self.helper.listen(self._process_message)\n\n\nif __name__ == \"__main__\":\n    abuseIPDBInstance = AbuseIPDBConnector()\n    abuseIPDBInstance.start()\n", "path": "abuseipdb/src/abuseipdb.py"}]}