Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception TypeError: 'expected string or Unicode object, NoneType found' #50

Open
saeedghx68 opened this issue Aug 7, 2016 · 14 comments

Comments

@saeedghx68
Copy link

saeedghx68 commented Aug 7, 2016

Hi I test this code

session = Session(hostname='x.x.x.x', community='PTSsnmpCacti', version=2, retries=3, timeout=40)
#for use change dslam port admin status:
session.set('1.3.6.1.2.1.2.2.1.7.101', '2')

I gave this error:
Exception TypeError: 'expected string or Unicode object, NoneType found' in <module 'threading' from '/usr/lib/python2.7/threading.pyc'> ignored

@mynever
Copy link

mynever commented Aug 8, 2016

Hi, try to check this in python 3.x version.

@saeedghx68
Copy link
Author

tnx @mynever dear ,My problem was solved with python3.x but i using python 2.7 .
Why is there a problem in Python2.7?

@mynever
Copy link

mynever commented Aug 9, 2016

truly saying, i've checked this oid in my enviroment.
everything is fine.

Python 2.7.10 (default, Mar 16 2016, 16:34:50) 
[GCC 4.9.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from easysnmp import Session
>>> session = Session(hostname='x.x.x.x', community='x', version=2, retries=3, timeout=40)
>>> session.set('1.3.6.1.2.1.2.2.1.7.1', '2')
True
>>> session.set('1.3.6.1.2.1.2.2.1.7.1', '1')
True
>>> 

Try to check your versions of easysnmp and python 2.7.

@saeedghx68
Copy link
Author

hi @mynever , tnx for reply
OS :Debian 8
Python : 2.7.9
easysnmp: 0.2.4
I was really confused

@mynever
Copy link

mynever commented Aug 9, 2016

btw, u can also try this one fork

@kamakazikamikaze
Copy link
Collaborator

@saeedghx68 Did you encounter this error while attempting to multithread your code?

@saeedghx68
Copy link
Author

Hi @kamakazikamikaze
No, I don't using multi-threading.

@AyoCross
Copy link

same error occurred to me(ubuntu16.04, python 2.7.9), when i use multiprocessing.Queue in a sub-tread.
It's OK in the main-thread. so weird.....if you have fixed this problem, please tell me...THX

@kamakazikamikaze
Copy link
Collaborator

This is similar to #34 where multi-threading does not work properly. Unfortunately I have not yet been able to look into these as they are currently low priority.

@AyoCross I would need to see some sample code to understand how you're using it. I assume that you're sharing sessions rather than results? When I was using using multiprocessing at my former workplace, we used multiprocessing.Manager.Queue instead to return SNMPVariables.

@saeedghx68 I would need to see a sample of the code you use as well. You say that this is not an issue in Python 3 but it is a problem in Python 2? I'm trying to understand how the threading module is being involved. Are you serializing/pickling anything?

@kamakazikamikaze
Copy link
Collaborator

kamakazikamikaze commented May 25, 2017

@AyoCross Are you using v0.2.4 or the latest commit? I'm able to duplicate this while running tests on Raspbian Jessie and macOS, but Mint/Ubuntu is returning just fine

@AyoCross
Copy link

@kamakazikamikaze my error occurred when i put unserializable object into Queue, not because easysnmp....sorry

@kamakazikamikaze
Copy link
Collaborator

@AyoCross No worries! If you haven't seen it already, maybe dill could help serialize it

@AyoCross
Copy link

@kamakazikamikaze THX, that helps me a lot.

@kamakazikamikaze
Copy link
Collaborator

@mynever I think the reason why you may have had that issue is that your MIBs weren't loaded fully in the threads.

I came across this error myself when I tried using the dotted notation, ex. .1.3.6.1.2.1.31.1.1.1.18.10101. I had to manually specify the SNMP type unless I went with the full MIB name, ex. easysnmp.snmp_set('.1.3.6.1.2.1.31.1.1.1.18.10101', 'testing', 's', hostname='192.168.1.1') instead of easysnmp.snmp_set('IF-MIB::ifAlias.10101', 'testing', hostname='192.168.1.1').

If you were having success in the main thread using dot-notation without specifying type, but not in a sub-thread, perhaps it's an environment variable that isn't set when threads are created, therefore your snmp.conf file and MIBs are not being loaded?

There's too much going on to say for certain, but that would be my best guess.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants