简体   繁体   English

API Python Smartsheet无法与SDK连接

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

I'm pretty new to Python and I'm trying to connect to smartsheet with API. 我是Python的新手,正尝试使用API​​连接到Smartsheet。 I have ran "pip install smartsheet-python-sdk" and it installed smartsheet as I can find it under "lib" 我已经运行了“ pip install smartsheet-python-sdk”,并且安装了smartsheet,因为我可以在“ lib”下找到它

This is code I have found and supposed to work(I replaced the token with the token) 这是我找到并应该起作用的代码(我将令牌替换为令牌)

# 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('')

It shows this error: 它显示此错误:

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'

Now I'm not sure what my next step is. 现在我不确定下一步是什么。 I think I have followed all of the appropriate steps. 我认为我已经遵循了所有适当的步骤。 When I run import smartsheet by itself it won't error out. 当我自己运行import smartsheet ,它不会出错。 What am I doing wrong? 我究竟做错了什么?

Thank you 谢谢

Update*** 更新***

After using the code from the github page and implementing my token and sheet id I get this error: 使用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

I printed ss and ss.Sheets and both do not reflect the actual token or sheet_id 我打印了ss和ss.Sheets,但它们都不能反映实际的标记或sheet_id

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

I suspect the problem is that you are using a local variable with the same name as the module ('smartsheet') 我怀疑问题在于您正在使用与模块名称相同的局部变量(“ smartsheet”)

Please take a look at the sample here: https://github.com/smartsheet-samples/python-read-write-sheet 请在这里查看示例: https : //github.com/smartsheet-samples/python-read-write-sheet

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

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