Python 2.6 -- paramiko import error - python

I have some scripts that run every 30 minutes in cron that import paramiko. Seemingly at random, I will get one of these two errors during import:
Traceback (most recent call last):
...
File "build/bdist.linux-x86_64/egg/paramiko/__init__.py", line 65, in <module>
File "build/bdist.linux-x86_64/egg/paramiko/transport.py", line 42, in <module>
File "build/bdist.linux-x86_64/egg/paramiko/packet.py", line 39, in <module>
File "build/bdist.linux-x86_64/egg/Crypto/Hash/HMAC.py", line 66, in <module>
File "build/bdist.linux-x86_64/egg/Crypto/Util/strxor.py", line 7, in <module>
File "build/bdist.linux-x86_64/egg/Crypto/Util/strxor.py", line 6, in __bootstrap__
ImportError: dynamic module does not define init function (initstrxor)
-- OR --
Traceback (most recent call last):
...
File "build/bdist.linux-x86_64/egg/paramiko/__init__.py", line 65, in <module>
File "build/bdist.linux-x86_64/egg/paramiko/transport.py", line 53, in <module>
File "build/bdist.linux-x86_64/egg/Crypto/Cipher/ARC4.py", line 66, in <module>
File "build/bdist.linux-x86_64/egg/Crypto/Cipher/_ARC4.py", line 7, in <module>
File "build/bdist.linux-x86_64/egg/Crypto/Cipher/_ARC4.py", line 6, in __bootstrap__
ImportError: dynamic module does not define init function (init_ARC4)
Every time that I have seen this issue, simply rerunning the script allows paramiko to import correctly and the script to finish.
What can cause this issue? Any help is greatly appreciated.

While I have no idea what may be causing the error, it seems it's failing on the native parts of pycrypto, so you may want to retry a couple of times:
from time import sleep
n_tries= 3
import_success= False
while not import_success:
try:
from Crypto.Cipher import Blowfish, AES, DES3, ARC4
from Crypto.Hash import MD5, SHA, SHA256, HMAC
from Crypto import Random
from Crypto.PublicKey import DSA, RSA
from Crypto.Util import Counter, number
import_success= True
except ImportError:
if not n_tries:
raise #re-raise ImportError
n_tries-=1
sleep(1)

Related

some problems of using Python's Cryptography on Windows

I would like to use the cryptography's module on Windows, I am using version 1.12 and Python 3.10.6, and I have some problems. Actually, when I run my script, I receive the error :
`
Traceback (most recent call last):
File "C:/Users/edoua/Documents/cryptographie.py", line 1, in <module>
from cryptography.fernet import Fernet
File "C:\Users\edoua\AppData\Local\Programs\Python\Python310\lib\site-packages\cryptography\fernet.py", line 16, in <module>
from cryptography.hazmat.primitives.hmac import HMAC
File "C:\Users\edoua\AppData\Local\Programs\Python\Python310\lib\site-packages\cryptography\hazmat\primitives\hmac.py", line 10, in <module>
from cryptography.hazmat.backends.openssl.hmac import _HMACContext
File "C:\Users\edoua\AppData\Local\Programs\Python\Python310\lib\site-packages\cryptography\hazmat\backends\openssl\__init__.py", line 6, in <module>
from cryptography.hazmat.backends.openssl.backend import backend
File "C:\Users\edoua\AppData\Local\Programs\Python\Python310\lib\site-packages\cryptography\hazmat\backends\openssl\backend.py", line 13, in <module>
from cryptography import utils, x509
File "C:\Users\edoua\AppData\Local\Programs\Python\Python310\lib\site-packages\cryptography\x509\__init__.py", line 7, in <module>
from cryptography.x509.base import (
File "C:\Users\edoua\AppData\Local\Programs\Python\Python310\lib\site-packages\cryptography\x509\base.py", line 28, in <module>
from cryptography.x509.extensions import (
File "C:\Users\edoua\AppData\Local\Programs\Python\Python310\lib\site-packages\cryptography\x509\extensions.py", line 25, in <module>
from cryptography.x509.general_name import (
File "C:\Users\edoua\AppData\Local\Programs\Python\Python310\lib\site-packages\cryptography\x509\general_name.py", line 9, in <module>
from email.utils import parseaddr
File "C:\Users/edoua/Documents\email.py", line 18, in <module>
server.login(email_address, email_password)
File "C:\Users\edoua\AppData\Local\Programs\Python\Python310\lib\smtplib.py", line 739, in login
(code, resp) = self.auth(
File "C:\Users\edoua\AppData\Local\Programs\Python\Python310\lib\smtplib.py", line 641, in auth
response = encode_base64(initial_response.encode('ascii'), eol='')
NameError: name 'encode_base64' is not defined
`
It is coming from the smtplib.py file. Also, I precise that the module works perfectly, I can use all the functions of the module base64. So the problem is coming from the word 'encode_base64'. Please help !
I tried to launch my program, and that error occures, I expected that it was going to work.
You have a local module C:\Users/edoua/Documents\email.py that is shadowing the email module from the Python standard library. Rename email.py to something else, or move it to somewhere that isn't on the Python path.

Python - ValueError: source code string cannot contain null bytes

I have a problem. I am using Windows 7 32x, Python 3.
When I try to import the numpy library in code, no matter what, I get an error. I don't remember how to solve it.
The code itself:
import numba
print('Hello World!')
And here is the error:
Traceback (most recent call last):
File "C:\Users\User\Desktop\numba_test.py", line 1, in <module>
import numba
File "C:\Users\User\AppData\Roaming\Python\Python37\site-packages\numba\__init__.py", line 38, in <module>
from numba.core.decorators import (cfunc, generated_jit, jit, njit, stencil,
File "C:\Users\User\AppData\Roaming\Python\Python37\site-packages\numba\core\decorators.py", line 12, in <module>
from numba.stencils.stencil import stencil
File "C:\Users\User\AppData\Roaming\Python\Python37\site-packages\numba\stencils\stencil.py", line 11, in <module>
from numba.core import types, typing, utils, ir, config, ir_utils, registry
File "C:\Users\User\AppData\Roaming\Python\Python37\site-packages\numba\core\registry.py", line 4, in <module>
from numba.core import utils, typing, dispatcher, cpu
File "C:\Users\User\AppData\Roaming\Python\Python37\site-packages\numba\core\dispatcher.py", line 13, in <module>
from numba.core import (
File "C:\Users\User\AppData\Roaming\Python\Python37\site-packages\numba\core\compiler.py", line 6, in <module>
from numba.core import (utils, errors, typing, interpreter, bytecode, postproc,
File "C:\Users\User\AppData\Roaming\Python\Python37\site-packages\numba\core\cpu.py", line 15, in <module>
import numba.core.entrypoints
File "C:\Users\User\AppData\Roaming\Python\Python37\site-packages\numba\core\entrypoints.py", line 8, in <module>
import importlib_metadata
ValueError: source code string cannot contain null bytes
I have reinstalled numba several times, searched for solutions on the Internet, but all without success. Help what you can.
import numbers
print('Hello World!')

Whenever I run my discord bot using discord.py I'm getting an AttributeError 'logging' has no attribute 'getlogger'

All my code is on github except for the token.py file for obvious reasons.
bot.py file
I have had similar issues in the past and have resolved them by reconstructing some code so I apologize in advance if this is another one of those issues where I missed a capital or something but I have tried all the obvious syntax issues and none of them seemed to work. Atom also didn't show any errors.
Here is the whole error message:
Traceback (most recent call last):
File "C:\Users\james\Documents\botpy\bot.py", line 5, in <module>
import discord
File "C:\Users\james\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\__init__.py", line 21, in <module>
import logging
File "C:\Users\james\AppData\Local\Programs\Python\Python38-32\lib\logging\__init__.py", line 26, in <module>
import sys, os, time, io, re, traceback, warnings, weakref, collections.abc
File "C:\Users\james\AppData\Local\Programs\Python\Python38-32\lib\traceback.py", line 5, in <module>
import linecache
File "C:\Users\james\AppData\Local\Programs\Python\Python38-32\lib\linecache.py", line 11, in <module>
import tokenize
File "C:\Users\james\AppData\Local\Programs\Python\Python38-32\lib\tokenize.py", line 34, in <module>
from token import *
File "C:\Users\james\Documents\botpy\token.py", line 2, in <module>
from discord.ext import commands
File "C:\Users\james\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\__init__.py", line 13, in <module>
from .bot import Bot, AutoShardedBot, when_mentioned, when_mentioned_or
File "C:\Users\james\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\bot.py", line 27, in <module>
import asyncio
File "C:\Users\james\AppData\Local\Programs\Python\Python38-32\lib\asyncio\__init__.py", line 8, in <module>
from .base_events import *
File "C:\Users\james\AppData\Local\Programs\Python\Python38-32\lib\asyncio\base_events.py", line 18, in <module>
import concurrent.futures
File "C:\Users\james\AppData\Local\Programs\Python\Python38-32\lib\concurrent\futures\__init__.py", line 8, in <module>
from concurrent.futures._base import (FIRST_COMPLETED,
File "C:\Users\james\AppData\Local\Programs\Python\Python38-32\lib\concurrent\futures\_base.py", line 42, in <module>
LOGGER = logging.getLogger("concurrent.futures")
AttributeError: partially initialized module 'logging' has no attribute 'getLogger' (most likely due to a circular import)
Try to rename your file into main.py
I had a similar error just because the filename.

What is this error code telling me? i.e. what do I need to fix

What does this error code mean? (see first answer for error code) I got this while attempting to open a csv file and read the first 5 rows of data.
C:\Users\torou>python cleandep/py
python: can't open file 'cleandep/py': [Errno 2] No such file or directory
C:\Users\torou>python http://cleandep.py
Traceback (most recent call last):
File "bit_generator.pyx", line 40, in numpy.random.bit_generator
File "C:\Users\torou\AppData\Local\Programs\Python\Python37-2\lib\http://secrets.py", line 20, in <module>
from random import SystemRandom
File "C:\Users\torou\http://random.py", line 1, in <module>
from random import random
ImportError: cannot import name 'random' from 'random' C:\Users\torou\http://random.py)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "http://cleandep.py", line 8, in <module>
import numpy as npy
File "C:\Users\torou\AppData\Local\Programs\Python\Python37-32\lib\site-packages\numpy\__init__.py", line 150, in <module>
from . import random
File "C:\Users\torou\AppData\Local\Programs\Python\Python37-32\lib\site-packages\numpy\random\__init__.py", line 181, in <module>
from . import _pickle
File "C:\Users\torou\AppData\Local\Programs\Python\Python37-32\lib\site-packages\numpy\random\_pickle.py", line 1, in <module>
from .mtrand import RandomState
File "mtrand.pyx", line 9, in init numpy.random.mtrand
File "mt19937.pyx", line 1, in init numpy.random.mt19937
File "bit_generator.pyx", line 43, in init numpy.random.bit_generator
File "C:\Users\torou\http://random.py", line 1, in <module>
from random import random
ImportError: cannot import name 'random' from 'random' C:\Users\torou\http://random.py)
This is the python 3 code i attempted to run:
import numpy as npy
import pandas as pd
data= pd.read_csv("cti-april02-log")
data.head()
you have a file named random.py that override the module with the same name from the standard library (i.e. it try to import random from your file random.py, not the module in the standard library

Theano tensor import error

I have been trying to import theano.tensor in my code.
I have used theano.tensor before. All of my previous code importing theano.tensor works perfectly in my machine. Now I am trying to write another script importing the tensor from theano and I am getting the following exception.
Traceback (most recent call last):
File "code.py", line 2, in <module>
import theano.tensor as T
File "/anaconda3/lib/python3.5/site-packages/theano/__init__.py", line 52, in <module>
from theano.gof import (
File "/anaconda3/lib/python3.5/site-packages/theano/gof/__init__.py", line 56, in <module>
from theano.gof.opt import (
File "/anaconda3/lib/python3.5/site-packages/theano/gof/opt.py", line 11, in <module>
import pdb
File "/anaconda3/lib/python3.5/pdb.py", line 75, in <module>
import code
File "/localtmp/saikat/CovInfo/Closure/code.py", line 2, in <module>
import theano.tensor as T
File "/anaconda3/lib/python3.5/site-packages/theano/tensor/__init__.py", line 6, in <module>
from theano.tensor.basic import *
File "/anaconda3/lib/python3.5/site-packages/theano/tensor/basic.py", line 17, in <module>
from theano.tensor import elemwise
File "/anaconda3/lib/python3.5/site-packages/theano/tensor/elemwise.py", line 13, in <module>
from theano import scalar
File "/anaconda3/lib/python3.5/site-packages/theano/scalar/__init__.py", line 2, in <module>
from .basic import *
File "/anaconda3/lib/python3.5/site-packages/theano/scalar/basic.py", line 25, in <module>
from theano import gof, printing
File "/anaconda3/lib/python3.5/site-packages/theano/printing.py", line 22, in <module>
from theano.compile import Function, debugmode, SharedVariable
File "/anaconda3/lib/python3.5/site-packages/theano/compile/__init__.py", line 9, in <module>
from theano.compile.function_module import *
File "/anaconda3/lib/python3.5/site-packages/theano/compile/function_module.py", line 22, in <module>
import theano.compile.mode
File "/anaconda3/lib/python3.5/site-packages/theano/compile/mode.py", line 77, in <module>
OPT_NONE = gof.Query(include=[], exclude=exclude)
AttributeError: module 'theano.gof' has no attribute 'Query'
I cannot find any plausible reason for this exception.
I guess i got your problem. See in the error log:
File "/anaconda3/lib/python3.5/pdb.py", line 75, in <module>
import code
I believe there is another script called code.py in Theano which gets called from pdb.py when python interpreter executes your script which is also named as code.py. I am guessing python interpreter is mixing up these two scripts and executing the wrong one! You can change the filename and check whether the error disappear or not.

Categories

Resources