Attribute error: module 'collections' has no attribute 'MutableSequence' PYTHON/SMARTSHEET SDK

Viewed 1571

I installed the Smartsheet Python sdk, imported the smartsheet module but am getting an error when I want to run the script. The error is localized to the smartsheet module and says that collections module is missing Mutable Sequence. I have already tried adding:

from collections.abc import MutableSequence

and had no change.

import smartsheet
import logging
import os

_dir = os.path.dirname(os.path.abspath(__file__))

This is what pops up in the terminal.

 File "C:\Users\jhorvath\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\smartsheet\smartsheet.py", line 34, in <module>
    from .models import Error, ErrorResult
  File "C:\Users\jhorvath\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\smartsheet\models\__init__.py", line 21, in <module>
    from .access_token import AccessToken
  File "C:\Users\jhorvath\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\smartsheet\models\access_token.py", line 20, in <module>
    from ..types import *
  File "C:\Users\jhorvath\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\smartsheet\types.py", line 29, in <module>
    class TypedList(collections.MutableSequence):
AttributeError: module 'collections' has no attribute 'MutableSequence'
3 Answers

A "quick and dirty" solution (I have this one - Python 3.10):
Path you-python-installation\python\Lib\site-packages\smartsheet
File types.py Line 29
class TypedList(collections.MutableSequence):

Replace with

class TypedList(collections.abc.MutableSequence):

I think Сolleagues from smartsheet - will fix the compatibility problem (at least - I believe it)
The main reason is Deprecated since version 3.3, will be removed in version 3.10

If you are not able to edit the package as recommended in the first solution, use Python 3.9 that is the last version to support collections Mutable Sequence.

Another solution I used is to modify the affected .py file in downloaded library from Smartsheet and change

import collections

to

import collections.abc as collections
Related