- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在编写代码以使用 python swift 客户端库访问对象存储。该程序的目的是使用 swift 客户端 API 读取、写入和删除对象存储中的 CSV 文件。我可以知道出了什么问题吗?我从网站上获得了这段代码。有没有其他方法可以从 python 访问对象存储?
import swiftclient.client
from keystoneclient import client
print 'i am fine'
conn = swiftclient.Connection(key="password",
authurl='https://identity.open.softlayer.com',
#auth_version='3',
os_options={"project_id": 'project-id',
"user_id": 'user_id',
"region_name": "dallas"})
container_name = 'test'
# File name for testing
file_name = 'result.csv'
# Create a new container
conn.put_container(container_name)
print "nContainer %s created successfully." % container_name
ERROR:swiftclient:Auth GET failed: https://identity.open.softlayer.com 300 Multiple Choices
Traceback (most recent call last):
File "/gpfs/fs01/user/s1ab-0eb9620648b3ce-07c8d52a704f/.local/lib/python2.7/site-packages/swiftclient/client.py", line 1553, in _retry
self.url, self.token = self.get_auth()
File "/gpfs/fs01/user/s1ab-0eb9620648b3ce-07c8d52a704f/.local/lib/python2.7/site-packages/swiftclient/client.py", line 1507, in get_auth
timeout=self.timeout)
File "/gpfs/fs01/user/s1ab-0eb9620648b3ce-07c8d52a704f/.local/lib/python2.7/site-packages/swiftclient/client.py", line 593, in get_auth
timeout=timeout)
File "/gpfs/fs01/user/s1ab-0eb9620648b3ce-07c8d52a704f/.local/lib/python2.7/site-packages/swiftclient/client.py", line 468, in get_auth_1_0
http_status=resp.status, http_reason=resp.reason)
ClientException: Auth GET failed: https://identity.open.softlayer.com 300 Multiple Choices
ClientException Traceback (most recent call last)
<ipython-input-5-3708d247f0cc> in <module>()
15
16 # Create a new container
---> 17 conn.put_container(container_name)
18 print "nContainer %s created successfully." % container_name
19
/gpfs/fs01/user/s1ab-0eb9620648b3ce-07c8d52a704f/.local/lib/python2.7/site-packages/swiftclient/client.pyc in put_container(self, container, headers, response_dict)
1641 """Wrapper for :func:`put_container`"""
1642 return self._retry(None, put_container, container, headers=headers,
-> 1643 response_dict=response_dict)
1644
1645 def post_container(self, container, headers, response_dict=None):
/gpfs/fs01/user/s1ab-0eb9620648b3ce-07c8d52a704f/.local/lib/python2.7/site-packages/swiftclient/client.pyc in _retry(self, reset_func, func, *args, **kwargs)
1551 try:
1552 if not self.url or not self.token:
-> 1553 self.url, self.token = self.get_auth()
1554 self.http_conn = None
1555 if self.service_auth and not self.service_token:
/gpfs/fs01/user/s1ab-0eb9620648b3ce-07c8d52a704f/.local/lib/python2.7/site-packages/swiftclient/client.pyc in get_auth(self)
1505 cacert=self.cacert,
1506 insecure=self.insecure,
-> 1507 timeout=self.timeout)
1508 return self.url, self.token
1509
/gpfs/fs01/user/s1ab-0eb9620648b3ce-07c8d52a704f/.local/lib/python2.7/site-packages/swiftclient/client.pyc in get_auth(auth_url, user, key, **kwargs)
591 cacert=cacert,
592 insecure=insecure,
--> 593 timeout=timeout)
594 elif auth_version in AUTH_VERSIONS_V2 + AUTH_VERSIONS_V3:
595 # We are handling a special use case here where the user argument
/gpfs/fs01/user/s1ab-0eb9620648b3ce-07c8d52a704f/.local/lib/python2.7/site-packages/swiftclient/client.pyc in get_auth_1_0(url, user, key, snet, **kwargs)
466 raise ClientException('Auth GET failed', http_scheme=parsed.scheme,
467 http_host=conn.host, http_path=parsed.path,
--> 468 http_status=resp.status, http_reason=resp.reason)
469 if snet:
470 parsed = list(urlparse(url))
***ClientException: Auth GET failed: https://identity.open.softlayer.com 300 Multiple Choices***
*****With auth_version enabled:*****
ERROR:swiftclient:Authorization Failure. Authorization failed: The resource could not be found. (HTTP 404)
Traceback (most recent call last):
File "/gpfs/fs01/user/s1ab-0eb9620648b3ce-07c8d52a704f/.local/lib/python2.7/site-packages/swiftclient/client.py", line 1553, in _retry
self.url, self.token = self.get_auth()
File "/gpfs/fs01/user/s1ab-0eb9620648b3ce-07c8d52a704f/.local/lib/python2.7/site-packages/swiftclient/client.py", line 1507, in get_auth
timeout=self.timeout)
File "/gpfs/fs01/user/s1ab-0eb9620648b3ce-07c8d52a704f/.local/lib/python2.7/site-packages/swiftclient/client.py", line 617, in get_auth
auth_version=auth_version)
File "/gpfs/fs01/user/s1ab-0eb9620648b3ce-07c8d52a704f/.local/lib/python2.7/site-packages/swiftclient/client.py", line 543, in get_auth_keystone
raise ClientException('Authorization Failure. %s' % err)
ClientException: Authorization Failure. Authorization failed: The resource could not be found. (HTTP 404)
i am fine
---------------------------------------------------------------------------
ClientException Traceback (most recent call last)
<ipython-input-21-d0874a2c5851> in <module>()
15
16 # Create a new container
---> 17 conn.put_container(container_name)
18 print "nContainer %s created successfully." % container_name
19
/gpfs/fs01/user/s1ab-0eb9620648b3ce-07c8d52a704f/.local/lib/python2.7/site-packages/swiftclient/client.pyc in put_container(self, container, headers, response_dict)
1641 """Wrapper for :func:`put_container`"""
1642 return self._retry(None, put_container, container, headers=headers,
-> 1643 response_dict=response_dict)
1644
1645 def post_container(self, container, headers, response_dict=None):
/gpfs/fs01/user/s1ab-0eb9620648b3ce-07c8d52a704f/.local/lib/python2.7/site-packages/swiftclient/client.pyc in _retry(self, reset_func, func, *args, **kwargs)
1551 try:
1552 if not self.url or not self.token:
-> 1553 self.url, self.token = self.get_auth()
1554 self.http_conn = None
1555 if self.service_auth and not self.service_token:
/gpfs/fs01/user/s1ab-0eb9620648b3ce-07c8d52a704f/.local/lib/python2.7/site-packages/swiftclient/client.pyc in get_auth(self)
1505 cacert=self.cacert,
1506 insecure=self.insecure,
-> 1507 timeout=self.timeout)
1508 return self.url, self.token
1509
/gpfs/fs01/user/s1ab-0eb9620648b3ce-07c8d52a704f/.local/lib/python2.7/site-packages/swiftclient/client.pyc in get_auth(auth_url, user, key, **kwargs)
615 insecure=insecure,
616 timeout=timeout,
--> 617 auth_version=auth_version)
618 else:
619 raise ClientException('Unknown auth_version %s specified.'
/gpfs/fs01/user/s1ab-0eb9620648b3ce-07c8d52a704f/.local/lib/python2.7/site-packages/swiftclient/client.pyc in get_auth_keystone(auth_url, user, key, os_options, **kwargs)
541 raise ClientException(msg)
542 except exceptions.AuthorizationFailure as err:
--> 543 raise ClientException('Authorization Failure. %s' % err)
544 service_type = os_options.get('service_type') or 'object-store'
545 endpoint_type = os_options.get('endpoint_type') or 'publicURL'
ClientException: Authorization Failure. Authorization failed: The resource could not be found. (HTTP 404)
最佳答案
您可以为身份验证端点提供多种选择。您应该指定 auth_version
并相应地调整 authurl
。只需将 '/v3' 附加到 authurl
就可以了。
这是一个使用“插入到代码 - 凭据”功能的小示例。
# Insert to code - credentials
credentials = {
'auth_url':'https://identity.open.softlayer.com',
'project':'xxx',
'project_id':'xxx',
'region':'dallas',
'user_id':'xxx',
'domain_id':'xxx',
'domain_name':'xxx',
'username':'xxx',
'password':"""xxx""",
'filename':'precipitation.csv',
'container':'notebooks',
'tenantId':'xxx'
}
# read CSV file from Object Storage
from StringIO import StringIO
import swiftclient.client as swiftclient
import pandas as pd
conn = swiftclient.Connection(
key=credentials['password'],
authurl=credentials['auth_url']+"/v3",
auth_version='3',
os_options={
"project_id": credentials['project_id'],
"user_id": credentials['user_id'],
"region_name": credentials['region']})
obj = conn.get_object(credentials['container'], credentials['filename'])
data_df = pd.read_csv(StringIO(obj[1]))
data_df.head()
# Create a new container
container_name = "new_container"
conn.put_container(container_name)
# Write CSV file to Object Storage
import csv
conn.put_object(credentials['container'], "precipitation_2.csv", data_df.to_csv(quoting=csv.QUOTE_ALL, index=False), content_type='text')
python-swiftclient
的替代方法是使用 requests
包并自己构建请求。看看这个示例笔记本:https://console.ng.bluemix.net/data/notebooks/samples/Precipitation%20Analysis
在“访问对象存储”部分,函数 get_file_content(credentials)
可用于读取文件。相应的 POST 或 DELETE 可以类似的方式实现。
关于python - bluemix : Python swift client library accessing object storage 上的授权问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37746762/
有没有办法在 .swift 文件(编译成 .swift 模块)中声明函数,如下所示: 你好.swift func hello_world() { println("hello world")
我正在尝试使用 xmpp_messenger_ios 和 XMPPFramework 在 iOS 上执行 MUC 这是加入房间的代码。 func createOrJoinRoomOnXMPP()
我想在我的应用程序上创建一个 3D Touch 快捷方式,我已经完成了有关快捷方式本身的所有操作,它显示正确,带有文本和图标。 当我运行这个快捷方式时,我的应用程序崩溃了,因为 AppDelegate
我的代码如下: let assetTag = Expression("asset_tag") let query2 = mdm.select(mdm[assetTag],os, mac, lastRe
我的 swift 代码如下所示 Family.arrayTuple:[(String,String)]? = [] Family.arrayTupleStorage:String? Family.ar
这是我的 JSON,当我读取 ord 和 uniq 数据时出现错误 let response2 : [String: Any] = ["Response":["status":"SUCCESS","
我想将 swift 扩展文件移动到 swift 包中。但是,将文件移动到 swift 包后,我遇到了这种错误: "Type 'NSAttributedString' has no member 'ma
使用CocoaPods,我们可以设置以下配置: pod 'SourceModel', :configurations => ['Debug'] 有什么方法可以用 Swift Package Manag
我正在 Xcode 中开发一个 swift 项目。我将其称为主要项目。我大部分都在工作。我在日期选择器、日期范围和日期数学方面遇到了麻烦,因此我开始了另一个名为 StarEndDate 的项目,其中只
这是 ObjectiveC 代码: CCSprite *progress = [CCSprite spriteWithImageNamed:@"progress.png"]; mProgressBar
我正在创建一个命令行工具,在 Xcode 中使用 Swift。我想使用一个类似于 grunt 的配置文件确实如此,但我希望它是像 Swift 包管理器的 package.swift 文件那样的快速代码
我假设这意味着使用系统上安装的任何 swift 运行脚本:#!/usr/bin/swift 如何指定脚本适用的解释器版本? 最佳答案 Cato可用于此: #!/usr/bin/env cato 1.2
代码说完全没问题,没有错误,但是当我去运行模拟器的时候,会出现这样的字样: (Swift.LazyMapCollection (_base:[ ] 我正在尝试创建一个显示报价的报价应用。 这是导入
是否可以在运行 Swift(例如 Perfect、Vapor、Kitura 等)的服务器上使用 RealmSwift 并使用它来存储数据? (我正在考虑尝试将其作为另一种解决方案的替代方案,例如 no
我刚开始学习编程,正在尝试完成 Swift 编程书中的实验。 它要求““编写一个函数,通过比较两个 Rank 值的原始值来比较它们。” enum Rank: Int { case Ace = 1 ca
在您将此问题标记为重复之前,我检查了 this question 它对我不起作用。 如何修复这个错误: error: SWIFT_VERSION '5.0' is unsupported, suppo
从 Xcode 9.3 开始,我在我的模型中使用“Swift.ImplicitlyUnwrappedOptional.some”包裹了我的字符串变量 我不知道这是怎么发生的,但它毁了我的应用程序! 我
这个问题在这里已经有了答案: How to include .swift file from other .swift file in an immediate mode? (2 个答案) 关闭 6
我正在使用 Swift Package Manager 创建一个应用程序,我需要知道构建项目的配置,即 Debug 或 Release。我试图避免使用 .xcodeproj 文件。请有人让我知道这是否
有一个带有函数定义的文件bar.swift: func bar() { println("bar") } 以及一个以立即模式运行的脚本foo.swift: #!/usr/bin/xcrun s
我是一名优秀的程序员,十分优秀!