Python AWS Sagemaker抛出错误“;“非法约束约束”概念;

Python AWS Sagemaker抛出错误“;“非法约束约束”概念;,python,amazon-web-services,Python,Amazon Web Services,目前,我正在尝试运行以下一段python代码: import sagemaker from sagemaker import get_execution_role import json import boto3 sess = sagemaker.Session() role = get_execution_role() bucket = "mastering-ml-aws" prefix = "chapter2/blazingtext" from

目前,我正在尝试运行以下一段python代码:

import sagemaker
from sagemaker import get_execution_role
import json
import boto3

sess = sagemaker.Session()
role = get_execution_role()

bucket = "mastering-ml-aws"

prefix = "chapter2/blazingtext"

from os.path import expanduser

SRC_PATH = expanduser("~") + '/SageMaker/mastering-ml-on-aws/chapter2/'

with open(SRC_PATH + 'dem.txt', 'r') as file:
    dem_text = ["__label__0 " + line.strip('\n') for line in file]

with open(SRC_PATH + 'gop.txt', 'r') as file:
    gop_text = ["__label__1 " + line.strip('\n') for line in file]
    
corpus = dem_text + gop_text
    
from sklearn.model_selection import train_test_split
corpus_train, corpus_test = train_test_split(corpus, test_size=0.25, random_state=42) 

corpus_train_txt = "\n".join(corpus_train)
corpus_test_txt = "\n".join(corpus_test)
with open('tweets.train', 'w') as file:
    file.write(corpus_train_txt)    
with open('tweets.test', 'w') as file:
    file.write(corpus_test_txt)    

train_path = prefix + '/train'
validation_path = prefix + '/validation'

sess.upload_data(path='tweets.train', bucket=bucket, key_prefix=train_path)
sess.upload_data(path='tweets.test', bucket=bucket, key_prefix=validation_path)

s3_train_data = 's3://{}/{}'.format(bucket, train_path)
s3_validation_data = 's3://{}/{}'.format(bucket, validation_path)

但是,我收到以下错误(显然是在
sess.upload\u数据(path='tweets.train',bucket=bucket,key\u prefix=train\u path)
部分):

未能将tweets.train上载到ml aws/chapter2/blazingtext/train/tweets.train:调用PutObject操作时发生错误(IllegalLocationConstraintException):ap-east-1位置约束与此请求发送到的特定于区域的端点不兼容。


但是,我已经将当前位置更改为
us-east-1
,但错误仍然存在。我想知道是否有人有同样的问题,以及如何解决它

您能否通过导入boto3 region=boto3.Session()验证您正在使用的区域。区域名称和检查它返回的区域值?@prabhakarredy it返回“us-east-1”但是当我运行代码中提到的部分时,它仍然抛出相同的错误。你能用s3=boto3.resource('s3')s3.create_bucket(bucket=bucket_name,CreateBucketConfiguration={'LocationConstraint':'us-east-1')创建s3 bucket吗在你的脚本中,看看它是否解决了问题?@prabhakarredy我试图运行你建议的命令,但花了30多分钟,没有完成单元格的运行。请尝试更改区域