I tried using usocket.IPPROTO_SEC for micropython however it does not seem available.
Is there anything else I should do to get access to usocket.IPPROTO_SEC?
Setup
I use this docker image.
Micropython version: 1.11
Description
The micropython docs say that usocket.IPPROTO_SEC is an available constant, however when I try to access it, it is not there.
The output below shows how I am trying to access it and what are the attributes available inside usocket.
MicroPython v1.11-10-g84f1067f7 on 2019-06-02; linux version
Use Ctrl-D to exit, Ctrl-E for paste mode
>>> import usocket
>>> usocket.IPPROTO_SEC
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'IPPROTO_SEC'
>>> usocket.
__class__ __name__ AF_INET AF_INET6
AF_UNIX MSG_DONTROUTE MSG_DONTWAIT SOCK_DGRAM
SOCK_RAW SOCK_STREAM SOL_SOCKET SO_BROADCAST
SO_ERROR SO_KEEPALIVE SO_LINGER SO_REUSEADDR
getaddrinfo inet_ntop inet_pton sockaddr
socket
Related
I'd experienced weird result when testing couchbase python SDK.
below is the source code and result:
# xxx.py
from gcouchbase.bucket import Bucket
dsn = 'couchbase://[url-of-couchbase]/[bucket-name]'
db = Bucket(dsn)
# yyy.py
import logbook
import git
from xxx import db
# python yyy.py
Traceback (most recent call last):
File "/home/username/env/local/lib/python2.7/site-packages/gcouchbase/iops_gevent10.py", line 88, in timer_event_factory
return GEventTimer()
TypeError: 'NoneType' object is not callable
[1] 8546 abort (core dumped) python yyy.py
The weird thing is, when I remove import git or import logbook from yyy.py, the error doesn't happen.
Is there any reason for this error? should any resource for couchdb be disposed?
An asynchronous event seems to arrive after the Bucket object has been removed. If you call bucket._close() explicitly, the script would not be crashed. Anyways, it looks like a bug of gcouchbase.
i'm a new python learner.
i'm trying to list my active serial ports with this simple code
import serial.tools.list_ports as port_list
ports = list(port_list.main())
for p in ports:
print (p)
this is the reasult
C:\Python27\python.exe C:/Users/tc34669/PycharmProjects/untitled/open_serial_port.py
COM1
COM3
2 ports found
Traceback (most recent call last):
File "C:/Users/tc34669/PycharmProjects/untitled/open_serial_port.py", line 2, in <module>
ports = list(port_list.main())
TypeError: 'NoneType' object is not iterable
Someone here knows how can i list these ports without this TypeError ?
thanks
According to the documentation of pySerial main() isn't actually a documented function you can use to get the info of all the ports. Try using the comports() function instead :
from serial.tools import list_ports
for p in list_ports.comports():
print(p)
If you want to print only the port numbers, (e.g COM1), try using the comport objects 'device' property:
from serial.tools import list_ports
for p in list_ports.comports():
print(p.device)
I have been trying to get my GalaxyS3 to play nice with Ubuntu12.04 to no avail. I've tried a bunch of different apps that dont work and now I'm trying to make one that does.
Now I am told that Samsung did some 'bad magic' with it's new devices and that I need to talk to it via the MTP protocol which Ubuntu cant do by default for whatever reason.
I like python so I'm trying this out using pymtp.
My current problem is that pymtp's connect function is failing:
import pymtp
oMTP = pymtp.MTP()
oMTP.connect()
This yields:
Device 0 (VID=04e8 and PID=6860) is a Samsung GT-P7310/P7510/N7000/I9100/Galaxy Tab 7.7/10.1/S2/Nexus/Note.
PTP_ERROR_IO: failed to open session, trying again after resetting USB interface
LIBMTP libusb: Attempt to reset device
LIBMTP PANIC: failed to open session on second attempt
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/pymodules/python2.7/pymtp.py", line 443, in connect
raise NoDeviceConnected
pymtp.NoDeviceConnected
I have an Arduino hooked up with 2 DS18B20 temp sensors. I'm very (VERY) new to python. I am looking for a way to read the serial input and parse it into a sqlite database, but that is getting ahead of myself. Why do I get an error while trying to define my serial port to a variable?
First things first sys.version
2.7.1 (r271:86832, Jul 31 2011, 19:30:53)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)]
My current, just read input from the serial connection program.
from serial import serial
import time
# open serial port
ser = serial.Serial('/dev/tty.usbmodem621',9600,timeout=2)
ser.open()
while True:
print('dev 0' + ser.read())
pass
ser.close()
I can not currently get it to compile. Most of the results I've found for this error tell to add from serial import serial, but in this case it hasn't worked.
The error.
$ python ser.py
Traceback (most recent call last):
File "ser.py", line 1, in <module>
from serial import serial
File "/Users/frankwiebenga/serial.py", line 8, in <module>
AttributeError: 'module' object has no attribute 'Serial'
Also if I just use import serial I get the same error
$ python ser.py
Traceback (most recent call last):
File "ser.py", line 1, in <module>
import serial
File "/Users/frankwiebenga/serial.py", line 8, in <module>
AttributeError: 'module' object has no attribute 'Serial'
Also, per comment. Created new file named something.py and still get the same error regardless of using import serial or from serial import serial.
$ python something.py
Traceback (most recent call last):
File "something.py", line 1, in <module>
from serial import serial
ImportError: No module named serial
When running my bash script I get an output that is valid, so I know it isn't the Arduino code.
Output:
Requesting temperatures...DONE
Device 0: 25.62
Device 1: 25.75
Requesting temperatures...DONE
Device 0: 25.62
Device 1: 25.81
Bash:
while true # loop forever
do
inputline="" # clear input
# Loop until we get a valid reading from AVR
until inputline=$(echo $inputline | grep -e "^temp: ")
do
inputline=$(head -n 1 < /dev/tty.usbmodem621)
done
echo "$inputline"
done
You need to use import serial. serial is the name of the module and it does not contain an attribute with name serial.
http://pyserial.sourceforge.net/shortintro.html#opening-serial-ports
You can EITHER do:
from serial import Serial
s = Serial(...)
OR:
import serial
s = serial.Serial(...)
Choose one.
You need do pip install pyserial instead of pip install serial (which does not run into an error but installs another module).
For this problem (stackoverflow.com/questions/4086435/), I tried to make a Python 3 version of the library python-websocket (github.com/mtah/python-websocket/), here is my code: https://gist.github.com/663175.
Blender comes with his own Python 3.1 package, so I added my file directly in its «site-packages» folder. I get this error now:
Traceback (most recent call last):
File "websocket.py", line 6, in
AttributeError: 'module' object has no attribute 'WebSocket'
when running this code in Blender:
import sys, os, asyncore, websocket
def msg_handler(msg):
print(msg)
socket = websocket.WebSocket('ws://localhost:8080/', onmessage=msg_handler)
socket.onopen = lambda: socket.send('Hello world!')
try:
asyncore.loop()
except KeyboardInterrupt:
socket.close()
I found that a __init__.py is needed so I added but it didn't help…
What I am doing wrong here ? Thanks for your help.
It looks like you called your script websocket.py, so the import of websocket finds the script itself, instead of the installed module by that name. Rename the script to something else (and if it created a websocket.pyc file, delete that.)