質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.46%
Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Amazon S3

Amazon S3 (Simple Storage Service)とはアマゾン・ウェブ・サービスが提供するオンラインストレージサービスです。

AWS(Amazon Web Services)

Amazon Web Services (AWS)は、仮想空間を機軸とした、クラスター状のコンピュータ・ネットワーク・データベース・ストーレッジ・サポートツールをAWSというインフラから提供する商用サービスです。

Q&A

解決済

1回答

985閲覧

Amazon ForecastをAWS SDK (Boto3) 経由で操作したい

退会済みユーザー

退会済みユーザー

総合スコア0

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Amazon S3

Amazon S3 (Simple Storage Service)とはアマゾン・ウェブ・サービスが提供するオンラインストレージサービスです。

AWS(Amazon Web Services)

Amazon Web Services (AWS)は、仮想空間を機軸とした、クラスター状のコンピュータ・ネットワーク・データベース・ストーレッジ・サポートツールをAWSというインフラから提供する商用サービスです。

0グッド

0クリップ

投稿2021/05/29 16:36

前提・実現したいこと

以下のサイトを参考に、amazon forecastを操作しています。
https://dev.classmethod.jp/articles/amazon-forecast-aws-sdk-boto3/#toc-12
ですが、create datasetの部分でエラーが起きてしまい、止まってしまいます。
具体的には、データセットの作成の34行目の部分です。

初歩的なものかも知れませんが、エラーの原因がわからないので、教えていただけますでしょうか?

発生している問題・エラーメッセージ

エラーメッセージ --------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-37-51134cf5f641> in <module> 2 datasetArn = create_dataset_response['DatasetArn'] 3 # データセットグループにデータセットを登録 ----> 4 forecast.update_dataset_group(DatasetGroupArn=datasetGroupArn, DatasetArns=[datasetArn]) NameError: name 'forecast' is not defined

該当のソースコード

python

1# データセットグループにデータセットを登録 2forecast.update_dataset_group(DatasetGroupArn=datasetGroupArn, DatasetArns=[datasetArn])

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

おはようございます。

問題文読ませていただきました。

forecastを定義していないことが原因だと思っております。

こちらの記事のこの部分をご自身の環境に合わせて変更すると、動きそうですね。

Python

1session = boto3.Session(region_name='us-west-2') 2forecast = session.client(service_name='forecast')

ご確認のほど、よろしくお願いいたします。????‍♂️

投稿2021/05/29 21:50

退会済みユーザー

退会済みユーザー

総合スコア0

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

退会済みユーザー

退会済みユーザー

2021/05/29 22:09

ご連絡ありがとうございます! KURORO様から頂いたアドバイスによって、forecastを定義することができました。ありがとうございました! 追加で申し訳ありませんが、forecastを定義した後、認証情報が見つからないというエラーが出てしまいます。これに関する理由などは考えられますでしょうか? エラーコードは以下のように出ています。 ### --------------------------------------------------------------------------- NoCredentialsError Traceback (most recent call last) <ipython-input-43-741242b9ed94> in <module> 4 datasetArn = create_dataset_response['DatasetArn'] 5 # データセットグループにデータセットを登録 ----> 6 forecast.update_dataset_group(DatasetGroupArn=datasetGroupArn, DatasetArns=[datasetArn]) ~/opt/anaconda3/lib/python3.8/site-packages/botocore/client.py in _api_call(self, *args, **kwargs) 355 "%s() only accepts keyword arguments." % py_operation_name) 356 # The "self" in this scope is referring to the BaseClient. --> 357 return self._make_api_call(operation_name, kwargs) 358 359 _api_call.__name__ = str(py_operation_name) ~/opt/anaconda3/lib/python3.8/site-packages/botocore/client.py in _make_api_call(self, operation_name, api_params) 660 http, parsed_response = event_response 661 else: --> 662 http, parsed_response = self._make_request( 663 operation_model, request_dict, request_context) 664 ~/opt/anaconda3/lib/python3.8/site-packages/botocore/client.py in _make_request(self, operation_model, request_dict, request_context) 680 def _make_request(self, operation_model, request_dict, request_context): 681 try: --> 682 return self._endpoint.make_request(operation_model, request_dict) 683 except Exception as e: 684 self.meta.events.emit( ~/opt/anaconda3/lib/python3.8/site-packages/botocore/endpoint.py in make_request(self, operation_model, request_dict) 100 logger.debug("Making request for %s with params: %s", 101 operation_model, request_dict) --> 102 return self._send_request(request_dict, operation_model) 103 104 def create_request(self, params, operation_model=None): ~/opt/anaconda3/lib/python3.8/site-packages/botocore/endpoint.py in _send_request(self, request_dict, operation_model) 130 def _send_request(self, request_dict, operation_model): 131 attempts = 1 --> 132 request = self.create_request(request_dict, operation_model) 133 context = request_dict['context'] 134 success_response, exception = self._get_response( ~/opt/anaconda3/lib/python3.8/site-packages/botocore/endpoint.py in create_request(self, params, operation_model) 113 service_id=service_id, 114 op_name=operation_model.name) --> 115 self._event_emitter.emit(event_name, request=request, 116 operation_name=operation_model.name) 117 prepared_request = self.prepare_request(request) ~/opt/anaconda3/lib/python3.8/site-packages/botocore/hooks.py in emit(self, event_name, **kwargs) 354 def emit(self, event_name, **kwargs): 355 aliased_event_name = self._alias_event_name(event_name) --> 356 return self._emitter.emit(aliased_event_name, **kwargs) 357 358 def emit_until_response(self, event_name, **kwargs): ~/opt/anaconda3/lib/python3.8/site-packages/botocore/hooks.py in emit(self, event_name, **kwargs) 226 handlers. 227 """ --> 228 return self._emit(event_name, kwargs) 229 230 def emit_until_response(self, event_name, **kwargs): ~/opt/anaconda3/lib/python3.8/site-packages/botocore/hooks.py in _emit(self, event_name, kwargs, stop_on_response) 209 for handler in handlers_to_call: 210 logger.debug('Event %s: calling handler %s', event_name, handler) --> 211 response = handler(**kwargs) 212 responses.append((handler, response)) 213 if stop_on_response and response is not None: ~/opt/anaconda3/lib/python3.8/site-packages/botocore/signers.py in handler(self, operation_name, request, **kwargs) 88 # this method is invoked to sign the request. 89 # Don't call this method directly. ---> 90 return self.sign(operation_name, request) 91 92 def sign(self, operation_name, request, region_name=None, ~/opt/anaconda3/lib/python3.8/site-packages/botocore/signers.py in sign(self, operation_name, request, region_name, signing_type, expires_in, signing_name) 160 raise e 161 --> 162 auth.add_auth(request) 163 164 def _choose_signer(self, operation_name, signing_type, context): ~/opt/anaconda3/lib/python3.8/site-packages/botocore/auth.py in add_auth(self, request) 355 def add_auth(self, request): 356 if self.credentials is None: --> 357 raise NoCredentialsError 358 datetime_now = datetime.datetime.utcnow() 359 request.context['timestamp'] = datetime_now.strftime(SIGV4_TIMESTAMP) NoCredentialsError: Unable to locate credentials ​ ### もしお分かりでしたら、ご対応いただけますでしょうか?
退会済みユーザー

退会済みユーザー

2021/05/30 05:37

本当にありがとうございました!認証を追加したところ、問題が解決しました! https://teratail.com/questions/341176?modal=q-comp もしお時間よろしければ、こちらのURLにて、質問がありますので、よろしくお願いします! 今回は本当にありがとうございました!
退会済みユーザー

退会済みユーザー

2021/05/30 07:14

お、ナイス自己解決です。 > https://teratail.com/questions/341176?modal=q-comp もしお時間よろしければ、こちらのURLにて、質問がありますので、よろしくお願いします! 時間があれば、チャレンジしてみます!! いえいえ。 また困ったこととかありましたら、気軽にご相談ください。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.46%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問