我正在尝试访问我的Watson数据平台目录中的一个csv文件。我使用了DSX笔记本中的代码生成功能:Insert to code > Insert StreamingBody object。
生成的代码是:
import os
import types
import pandas as pd
import boto3
def __iter__(self): return 0
# @hidden_cell
# The following code accesses a file in your IBM Cloud Object Storage. It includes your credentials.
# You might want to remove those credentials before you share your notebook.
os.environ['AWS_ACCESS_KEY_ID'] = '******'
os.environ['AWS_SECRET_ACCESS_KEY'] = '******'
endpoint = 's3-api.us-geo.objectstorage.softlayer.net'
bucket = 'catalog-test'
cos_12345 = boto3.resource('s3', endpoint_url=endpoint)
body = cos_12345.Object(bucket,'my.csv').get()['Body']
# add missing __iter__ method so pandas accepts body as file-like object
if not hasattr(body, "__iter__"): body.__iter__ = types.MethodType(__iter__, body)
df_data_2 = pd.read_csv(body)
df_data_2.head()当我试图运行这段代码时,我得到:
/usr/local/src/conda3_runtime.v27/4.1.1/lib/python3.5/site-packages/botocore/endpoint.py in create_endpoint(self, service_model, region_name, endpoint_url, verify, response_parser_factory, timeout, max_pool_connections)
270 if not is_valid_endpoint_url(endpoint_url):
271
--> 272 raise ValueError("Invalid endpoint: %s" % endpoint_url)
273 return Endpoint(
274 endpoint_url,
ValueError: Invalid endpoint: s3-api.us-geo.objectstorage.service.networklayer.com奇怪的是,如果我为SparkSession安装程序生成代码,则使用相同的端点,但火花代码运行正常。
我怎样才能解决这个问题?
我假设其他软层端点也会遇到同样的问题,所以我在这里也列出它们,以确保这个问题也适用于其他Softlayer位置:
发布于 2018-02-05 14:54:02
解决方案是在端点前缀加上https://,从.
这
endpoint = 's3-api.us-geo.objectstorage.softlayer.net'至
endpoint = 'https://s3-api.us-geo.objectstorage.softlayer.net'发布于 2018-02-06 06:24:35
对于,它应该是import ibm_boto3而不是import boto3。原始的boto3用于访问AWS,它使用不同的身份验证。也许这两者对端点值有不同的解释。
https://stackoverflow.com/questions/48625239
复制相似问题