base64 library for circuitpython on SEEED Xiao ESP32-C3 - base64

I'm trying to import base64 on the SEEED Xiao ESP32-C3 which is running circuitpython version 8 beta 6. However, when I use import base64 or import ubase64 I see the error ImportError: no module named 'base64' which is the same for ubase64. The only option was to use !pip install circuitpython-base64 which does not include b32decode. I read that base64 comes with Python by default which does not seem to be the case here. Is there any workaround?

circuitpython-base64 does include b32decode! If you want to take a look at the source it is here. After running pip install circuitpython-base64, the following script should work.
import circuitpython_base64 as base64
bytes_to_encode = b"Aladdin:open sesame"
print(repr(bytes_to_encode))
base32_string = base64.b32encode(bytes_to_encode)
print(repr(base32_string))
decoded_bytes = base632.b32decode(base32_string)
print(repr(decoded_bytes))

Related

cannot import module imageio in python3

Using python3, I am unable to import the imageio module into my python program, which I need, as I try to animate a list of PNG images I have. Thus far I have tried:
"pip3 install imageio" both running as myself and as root. The install succeeded, but it still errors out as in the subject line. I suppose I could try "apt-get install (package name)", but need to determine the package_name.
Any ideas more than welcome - TIA.
Try importing the last version.
import imageio.v3 as iio
im = iio.imread('imageio:chelsea.png')
print(im.shape) # (300, 451, 3)
ref https://imageio.readthedocs.io/en/stable/examples.html

Installing SOAPpy in Python 3

I'm trying to install SOAPpy library in python 3 . I get the following error
"/../Downloads/SOAPpy-0.11.6/SOAPpy/__init__.py", line 3, in <module>
from version import __version__
ModuleNotFoundError: No module named 'version'
I tried to install the other alternative that has been suggested in the other posts , e.g. zeep . But the url that I have to use has soap in it and is not working with the other alternatives.
The following is the example script that I am using from here
#!/usr/bin/python
import string
import hashlib
from SOAPpy import WSDL ## for extracting the URL of the endpoint (server script) from the WSDL file
from SOAPpy import SOAPProxy ## for usage without WSDL file
#1) Usage with WSDL (for extracting the URL of the endpoint)
wsdl = "https://www.brenda-enzymes.org/soap/brenda.wsdl"
password = hashlib.sha256("myPassword").hexdigest()
client = WSDL.Proxy(wsdl)
parameters = "j.doe#example.edu,"+password+",ecNumber*1.1.1.1#organism*Homo sapiens#"
resultString = client.getKmValue(parameters)
print resultString
I would like to ask for suggestions on how this can be resolved.
The version module is part of the SOAPpy package, but in Python 3 you'd need to use absolute imports,
from SOAPpy.version import __version__
or
from .version import __version__ in your __init__ installer package file.
There will be other issues with the code too.
Here's a link which supports SOAPpy for python3 https://pypi.org/project/SOAPpy-py3/

issue plotting .cap files ScaPy Python3

After reading .cap file using rdpcap successfully, I've been trying to use the function pdfdump but it keeps giving me an error:
"AttributeError: 'SingleTexRunner' object has no attribute 'texoutput' "
here's my code:
from scapy.all import *
import pyx
a = rdpcap("the file path..")
a.pdfdump("output filename")
anyone got an idea how to solve this issue?
Use sudo apt-get install python3-pyx on Linux(Debian, Ubuntu...) to install pyx and its dependencies; installing pyx with pip install pyx is not enough.
I'm using Python 3.6.0
I've installed scapy with:
pip3 install scapy-python3
Using wireshark 2.2.3, I saved a dump using the default file format which is .pcapng
I've used the same code as you :
from scapy.all import *
import pyx
a = rdpcap("test.pcapng")
a.pdfdump("test.pdf")
and I obtain a valid pdf.
Don't run scapy (if you use the command line) or your script as root. This fixed it for me.

Python 3: No module named zlib?

I am trying to run my Flask application with an Apache server using mod_wsgi, and it has been a bumpy road, to say the least.
It has been suggested that I should try to run my app's .wsgi file using Python to make sure it is working.
This is the contents of the file:
#!/usr/bin/python
activate_this = '/var/www/Giveaway/Giveaway/venv/bin/activate_this.py'
with open(activate_this) as f:
code = compile(f.read(), "somefile.py", 'exec')
exec(code)
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/Giveaways/")
from Giveaways import application
application.secret_key = 'Add your secret key'
However, when I run it, I get this error:
ImportError: No module named 'zlib'
And no, I am not using some homebrewed version of Python - I installed Python 3 via apt-get.
Thanks for any help.
does the contents of somefile.py include the gzip package? in which case you may have to install gzip package via pip or similar

Python 3.4 import gcm raise a SystemError: Parent module '' not loaded, cannot perform relative import

I'm trying to import gcm as following:
from . import gcm
And i get:
SystemError: Parent module '' not loaded, cannot perform relative import
I tried also called:
from gcm import GCM
by pip install python-gcm but i get the follwoing error:
module' object has no attribute 'GCM
Don't use the relative import syntax, from . import gcm. Instead, put the library where the Python interpreter can find it (via pip install python-gcm) and call from gcm import GCM in your program.
However, if you still get an error while attempting to import, you should add a comment to the project's open Python3 import issue thread on GitHub and let them know, since there still appears to be some ambiguity if this bug has been fixed yet or not.
Make it run temporarily
python-gcm depends on the requests package. Make sure it is installed. Invoke pip install requests to install it.
Download the ZIP archive of the master branch.
Extract the archive into a folder python-gcm-master.
Patch the file python-gcm-master/gcm/__init__.py. Use
import gcm
#GCM = gcm.GCM
instead of
import gcm
GCM = gcm.GCM
In this folder create a python file test.py. This file should contain example code from the python-gcm package:
from gcm.gcm import GCM
gcm = GCM(API_KEY)
data = {'param1': 'value1', 'param2': 'value2'}
# Plaintext request
reg_id = '12'
gcm.plaintext_request(registration_id=reg_id, data=data)
# JSON request
reg_ids = ['12', '34', '69']
response = gcm.json_request(registration_ids=reg_ids, data=data)
# Extra arguments
res = gcm.json_request(
registration_ids=reg_ids, data=data,
collapse_key='uptoyou', delay_while_idle=True, time_to_live=3600
)
Run this file using python3 test.py. Be aware that the example uses from gcm.gcm import GCM instead of the default from gcm import GCM
If an gcm.gcm.GCMAuthenticationException is thrown, you can see that it is imported correctly and you need to adjust your API_KEY. Adjust the test.py file according to your needs.
Make it run permanently
As far as you tried a relative import, I think you already came across issue 65. Apparently they broke the import mechanism for python3. However, it works per default on python2, but it is buggy with python3. The issue in the issue tracker is still open.

Resources