Sha-3 in python implementation - python

I am trying to implement sha-3 in python.The code given below is how I implemented it.But i am getting the below error again and again.
import sys
import hashlib
arg1 = sys.argv[1]
with open(arg1, 'r') as myfile:
data=myfile.read().replace('\n', '')
import sha3
s=hashlib.sha3_228(data.encode('utf-8')).hexdigest()
print(s)
The following error is what i get when I execute it.
Traceback (most recent call last):
File "sha3.py", line 6, in <module>
import sha3
File "/home/hello/Documents/SHA-3/sha3.py", line 7, in <module>
s=hashlib.sha3_228(data.encode('utf-8')).hexdigest()
AttributeError: 'module' object has no attribute 'sha3_228'
The below link can be used for reference.
https://pypi.python.org/pypi/pysha3

There are two problems here: one from your code, and one from the documentation, that contains a typo on the function you would like to use.
You are calling a function that is not present in hashlib library. You want to call function sha3_228 from module sha3, that is shipped with package pysha3. In fact, sha3_228 does not exist, it is sha3_224 that exists.
Simply replace hashlib.sha3_228 with sha3.sha3_224.
And make sure you have installed pysha3, with command
python -m pip install pysha3
Here is an example
import sha3
data='maydata'
s=sha3.sha3_224(data.encode('utf-8')).hexdigest()
print(s)
# 20faf4bf0bbb9ca9b3a47282afe713ba53c9e243bc8bdf1d670671cb

I had the same problem. I installed sha3 by itself first. That doesn't work. Then I installed pysha3 and it still didn't work. I finally uninstalled both sha3 and pysha3. Then I reinstalled just pysha3 and it worked fine.

You likely need to include:
import sys
if sys.version_info < (3, 6):
import sha3
This is because is lower versions of python sha3 aren't included by default in hashlib.

Related

ModuleNotFoundError: No module named 'h2oaicore'

I am following the tutorial of driverless: Driverless AI Standalone Python Scoring Pipeline, you can check it in the following link:
http://docs.h2o.ai/driverless-ai/latest-stable/docs/userguide/scoring-standalone-python.html#tar-method-py
I am performing:
Running Python Scoring Process - Recommended
but, when running the last step:
DRIVERLESS_AI_LICENSE_KEY = "pastekey here" SCORING_PIPELINE_INSTALL_DEPENDENCIES = 0 /path/to/your/dai-env.sh ./run_example.sh
the following error happens:
Traceback (most recent call last): File "example.py", line 7, in
from scoring_h2oai_experiment_5fd7ff9c_b11a_11eb_b91f_0242ac110002 import Scorer File
"/usr/local/lib/python3.6/dist-packages/scoring_h2oai_experiment_5fd7ff9c_b11a_11eb_b91f_0242ac110002/init.py",
line 1, in
from .scorer import Scorer File "/usr/local/lib/python3.6/dist-packages/scoring_h2oai_experiment_5fd7ff9c_b11a_11eb_b91f_0242ac110002/scorer.py",
line 7, in
from h2oaicore import application_context
ModuleNotFoundError: No module named 'h2oaicore'
--
Hope you can help me, thanks in advance.
Apparently it doesn't find your h20aicore module. One brute force method to import it could be do the following in your python script:
import sys
import os
sys.path.append(os.path.abspath("path/to/module"))
or alternatively you should add it to your python path.
I agree with #BlackPhoenix's comment. It is looking for h2oaicore module. The DAI Python scoring pipeline comes with a h2oaicore .whl file. Check out the shell script, run_example.sh. It should contain steps about pip installing h2oaicore.

Python tempfile.mkstemp(): AttributeError: 'function' object has no attribute 'mkstemp'

Not my code, I was trying a tool that includes the osascript library.
In the lib, at the line path = temp.tempfile() the error in the title is raised.
The temp library, correctly imported by the authors, has the following code itself:
f, path = tempfile.mkstemp()
The tempfile.mkstemp() part works like a charm.
So, since we are talking about two very common and widely used libs and since I'm apparently unable to find anything relevant on Google, I'm kind pretty sure there's some problem with my local configuration.
I'm on macOS, using python3 (3.7), no virtual envs.
The command pip list --outdated tells me that exactly those two libs are actually outdated, but apparently there is no way pip will download the updated versions. (note: my pip is correctly referring to the python3 binary, not macOS outdated python 2.7)
osascript 0.0.0 2020.7.2 sdist
temp 0.0.0 2020.7.1 sdist
Any ideas?
Steps to reproduce the error:
>>> import temp
>>> temp.tempfile()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.7/site-packages/temp/__init__.py", line 15, in tempfile
f, path = tempfile.mkstemp()
AttributeError: 'function' object has no attribute 'mkstemp'
This is a bug in package temp which is a dependency of osascript. The package imports tempfile and then immediately overwrites it with a function tempfile. Report the bug.

import yaml missing error module

>>> import yaml
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/tools/python_libs/yaml/__init__.py", line 2, in <module>
from error import *
ModuleNotFoundError: No module named 'error'
I don't see how to set my PYTHONPATH with anaconda3.
Am I missing an install step?
I have the same situation, but with the ROS. The same error reproduces when you use python 3 instead of python 2. You can see corresponding discussion
here. For some reasons I would like to use python3 instead of python2, so I need to find out, how to get rid of this error.
I can suggest two solutions right now:
Either use python2 instead of python3, as suggested in ROS discussion
Or try to install yaml with pip3 for python3 (not pip). I think it may help in this situation. See here for installation instructions.

PyPI Module not working

So today i started working on a simple python module, but i cant make it work.
the module itself works, but when i have uploaded it to PyPI and i then install it using Pip, it wont work.
Please notice that it is built for python-2.7
The source code can be seen here:
https://github.com/1m0r74l17y/FortyTwo
and it can be downloaded using:
sudo pip install FortyTwo
whenever i try to run a test program like this:
from FortyTwo import *
FortyTwo.nope()
It just gives me an error:
Traceback (most recent call last):
File "test.py", line 3, in
FortyTwo.nope()
AttributeError: 'module' object has no attribute 'fortytwo'
I would really appreciate any help, as it might lead me onto what i have to do to fix the problem.
You would need to do the following.
from FortyTwo import fortytwo
fortytwo.nope()
If you want to call nope directly from FortyTwo you would need to import that function in __init__.py.
e.g.
from FortyTwo.fortytwo import nope
def Start():
"""No Clue what to add here"""
What if you do
from FortyTwo import fortytwo
fortytwo.nope()
* credits to eandersson.

Python Standard Library not installed?

I'm fairly new to Python and recently started development on a new mac mini. As you know it comes with 2.7 installed.
The problem I'm running across is the Standard Library doesn't seem to be installed.
I get a syntax error when importing modules (SyntaxError: invalid syntax).
I was running this code with the argv datafile.csv
import csv
import sys
stocks.csv = argv
f = open(sys.argv[1], 'rt')
try:
reader = csv.reader(f)
for row in reader:
print row
finally:
f.close()
After awhile of this I decided to run the interpreter and get help.
When I ran the interpreter and do help(csv) or most other modules (sys works just fine) I get this error:
>>> import csv
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "csv.py", line 1
import
^
SyntaxError: invalid syntax
Do I need to install the library or am I accessing it wrong?
Thanks.
Do you have a file in the current directory named csv.py with a blank import statement on line 1? Python searches the current directory for imports before it looks at system directories.
importing module that can not be found causing
ImportError: No module named {...}
error SyntaxError means that text in file "csv.py" isn't valid python code.
Maybe you have your own "csv.py" somewhere that is shadowing original csv lib?

Categories