NetApp / ontap-rest-python

This repository contains sample code illustrating how to access the ONTAP REST API using Python. This Repository also contains ONTAPI Usage reporting code that helps to identify ONTAPI usage in your environment using ONTAP REST APIs.
BSD 3-Clause "New" or "Revised" License
60 stars 41 forks source link

module 'base64' has no attribute 'encodestring' when running svm_operations.py #34

Closed ashwinwriter closed 11 months ago

ashwinwriter commented 2 years ago

Encountered this error: Module 'base64' has no attribute 'encodestring' when running svm_operations.py

Located here: ontap-rest-python/examples/rest_api/utils.py

I managed to get this fixed, but wanted to share my observation and ask you if the change I made is correct ?

[root@centos9 tmp]# python3.9 svm_operations.py -c x.x.x.x -u admin -p xxxx Traceback (most recent call last): File "/tmp/svm_operations.py", line 421, in main() File "/tmp/svm_operations.py", line 415, in main headers = setup_connection(args.api_user, args.api_pass) File "/tmp/utils.py", line 82, in setup_connection base64string = base64.encodestring( AttributeError: module 'base64' has no attribute 'encodestring' [root@centos9 tmp]#

Googled, I found: base64.encodestring() deprecated since Python 3.1. Use base64.encodebytes() instead.

I edited the utils.py file and change the code at Line: 82:

From, base64string = base64.encodestring

To, base64string = base64.encodebytes

It worked this time: [root@centos9 tmp]# python3.9 svm_operations.py -c x.x.x.x -u admin -p xxxxx

Demonstrates SVM Operations using REST API:-

What SVM Operation would you like to do? [list/create/update/start/stop/delete] list

List of SVMs:-

svm_nfs

RobertBlackhart commented 2 years ago

Yes, I would think that is the right way to go. These scripts wouldn't work on versions prior to 3.5 anyway.

If you want to submit a pull request with that change, I will accept it.

ashwinwriter commented 2 years ago

Ok, makes sense. Thanks Rob. Yes, I would like to submit a pull request with this change but not sure how it works, I do see a tab for 'pull requests' in the menu. So let me give it a try. Thanks!

noorbuchi commented 11 months ago

Cleaning up stale issues