繁体   English   中英

API Python Smartsheet无法与SDK连接

[英]API Python smartsheet can't connect with SDK

我是Python的新手,正尝试使用API​​连接到Smartsheet。 我已经运行了“ pip install smartsheet-python-sdk”,并且安装了smartsheet,因为我可以在“ lib”下找到它

这是我找到并应该起作用的代码(我将令牌替换为令牌)

# Import.
import smartsheet

# Instantiate smartsheet and specify access token value.
smartsheet = smartsheet.Smartsheet('Token_here')

# Get all columns.
action = smartsheet.Sheets.get_columns('Template for Bram', include_all=True)
columns = action.data

# For each column, print Id and Title.
for col in columns:
    print(col.id)
    print(col.title)
    print('')

它显示此错误:

Traceback (most recent call last):
  File "C:\Users\bram\Desktop\smartsheet.py", line 2, in <module>
    import smartsheet
  File "C:\Users\bram\Desktop\smartsheet.py", line 5, in <module>
    smartsheet = smartsheet.Smartsheet('token_here')
AttributeError: 'module' object has no attribute 'Smartsheet'

现在我不确定下一步是什么。 我认为我已经遵循了所有适当的步骤。 当我自己运行import smartsheet ,它不会出错。 我究竟做错了什么?

谢谢

更新***

使用github页面上的代码并实现我的令牌和工作表ID后,出现此错误:

Traceback (most recent call last):
  File "C:\Users\bvanhout\Desktop\test23.py", line 58, in <module>
    sheet = ss.Sheets.get_sheet(sheet_id)
  File "C:\Python27\lib\site-packages\smartsheet\sheets.py", line 460, in get_sheet
    response = self._base.request(prepped_request, expected, _op)
  File "C:\Python27\lib\site-packages\smartsheet\smartsheet.py", line 178, in request
    res = self.request_with_retry(prepped_request, operation)
  File "C:\Python27\lib\site-packages\smartsheet\smartsheet.py", line 242, in request_with_retry
    return self._request(prepped_request, operation)
  File "C:\Python27\lib\site-packages\smartsheet\smartsheet.py", line 210, in _request
    raise UnexpectedRequestError(rex.request, rex.response)
UnexpectedRequestError: (<PreparedRequest [GET]>, None)


# TODO: Update this with the ID of your sheet to update
sheet_id = 48568543424234

我打印了ss和ss.Sheets,但它们都不能反映实际的标记或sheet_id

>>> print (ss.Sheets)
<smartsheet.sheets.Sheets object at 0x0000000003874438>

我怀疑问题在于您正在使用与模块名称相同的局部变量(“ smartsheet”)

请在这里查看示例: https : //github.com/smartsheet-samples/python-read-write-sheet

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM