Accessing arduino cloud api via python giving error 405

Hi all! I'm trying to access my arduino cloud via the python api. I tried following the tutorial in the docs at https://docs.arduino.cc/arduino-cloud/api/arduino-iot-api/ however when I use the script they suggest on there it get an error 405 with reason: Method Not Allowed. (see full stacktrace below). I've checked my api keys and even making the same request through postman which all seems to work fine (mostly). I do have an organization so im wondering if the issue is because theres no clarification for personal vs org account but i'm not entirely sure how i'd add that. I can add the python code if you're curious (its essentially the copy paste from the website). Thanks in advance! Stacktrace:
Exception when calling ThingsV2Api->list_things: (405)
Reason: Method Not Allowed
HTTP response headers: HTTPHeaderDict({'Content-Type': 'application/vnd.goa.error+json', 'Content-Length': '141', 'Connection': 'keep-alive', 'Date': 'Sat, 31 May 2025 23:45:42 GMT', 'Vary': 'Origin', 'Allow': 'OPTIONS', 'Cache-Control': 'no-cache, no-store, must-revalidate', 'Expires': '0', 'Pragma': 'no-cache', 'X-Cache': 'Error from cloudfront', 'Via': '1.1 da745b01c27611dac38d175371cb7b54.cloudfront.net (CloudFront)', 'X-Amz-Cf-Pop': 'DEN53-P2', 'X-Amz-Cf-Id': 'OFYJ8LmFIvLVooTXoYKu52oexBpmjJ9BTyVpXrTbvWdTeVg3TgqXpg=='})
HTTP response body: {"id":"hupCnj98","code":"method_not_allowed","status":405,"detail":"Method GET must be OPTIONS","meta":{"allowed":"OPTIONS","method":"GET"}}
Exception when calling ThingsV2Api->list_things: (405)
Reason: Method Not Allowed
HTTP response headers: HTTPHeaderDict({'Content-Type': 'application/vnd.goa.error+json', 'Content-Length': '141', 'Connection': 'keep-alive', 'Date': 'Sat, 31 May 2025 23:45:42 GMT', 'Vary': 'Origin', 'Allow': 'OPTIONS', 'Cache-Control': 'no-cache, no-store, must-revalidate', 'Expires': '0', 'Pragma': 'no-cache', 'X-Cache': 'Error from cloudfront', 'Via': '1.1 da745b01c27611dac38d175371cb7b54.cloudfront.net (CloudFront)', 'X-Amz-Cf-Pop': 'DEN53-P2', 'X-Amz-Cf-Id': 'OFYJ8LmFIvLVooTXoYKu52oexBpmjJ9BTyVpXrTbvWdTeVg3TgqXpg=='})
HTTP response body: {"id":"hupCnj98","code":"method_not_allowed","status":405,"detail":"Method GET must be OPTIONS","meta":{"allowed":"OPTIONS","method":"GET"}}
2 Replies
DarwinWasW
DarwinWasW5d ago
Code for http? The error says you are not using get, are you using post ?
Thoride
ThorideOP5d ago
from oauthlib.oauth2 import BackendApplicationClient
from requests_oauthlib import OAuth2Session

from os import access
import iot_api_client as iot
from iot_api_client.rest import ApiException
from iot_api_client.configuration import Configuration

# Get your token

oauth_client = BackendApplicationClient(client_id="client_id")
token_url = "https://api2.arduino.cc/iot/v1/clients/token"

oauth = OAuth2Session(client=oauth_client)
token = oauth.fetch_token(
token_url=token_url,
client_id="client_id",
client_secret="client_secret",
include_client_id=True,
audience="https://api2.arduino.cc/iot",
)

# store access token in access_token variable
access_token = token.get("access_token")

# configure and instance the API client with our access_token

client_config = Configuration(host="https://api2.arduino.cc/iot")
client_config.access_token = access_token
client = iot.ApiClient(client_config)
thing_id = "thing_id"

# as an example, interact with the properties API
api = iot.PropertiesV2Api(client)

try:
resp = api.properties_v2_list(thing_id)
print(resp)
except ApiException as e:
print("Got an exception: {}".format(e))
from oauthlib.oauth2 import BackendApplicationClient
from requests_oauthlib import OAuth2Session

from os import access
import iot_api_client as iot
from iot_api_client.rest import ApiException
from iot_api_client.configuration import Configuration

# Get your token

oauth_client = BackendApplicationClient(client_id="client_id")
token_url = "https://api2.arduino.cc/iot/v1/clients/token"

oauth = OAuth2Session(client=oauth_client)
token = oauth.fetch_token(
token_url=token_url,
client_id="client_id",
client_secret="client_secret",
include_client_id=True,
audience="https://api2.arduino.cc/iot",
)

# store access token in access_token variable
access_token = token.get("access_token")

# configure and instance the API client with our access_token

client_config = Configuration(host="https://api2.arduino.cc/iot")
client_config.access_token = access_token
client = iot.ApiClient(client_config)
thing_id = "thing_id"

# as an example, interact with the properties API
api = iot.PropertiesV2Api(client)

try:
resp = api.properties_v2_list(thing_id)
print(resp)
except ApiException as e:
print("Got an exception: {}".format(e))
like i said its literally the copy paste from the site i've got it to work via a normal request (using the requests package) so idk why it wont work via the iot stuff

Did you find this page helpful?