Scapy AttributeError on every call: 'module' object has no attribute '*' - python

I have installed Scapy from the package repos on my Ubuntu machine (Python 2.7), and I am trying to run this code from a file:
import scapy
dg = scapy.IP()
pcap = scapy.rdpcap("../tst/Http.cap")
scapy.send(IP())
Running gives the error,
AttributeError: 'module' object has no attribute 'IP'
Comment out the IP call on line 3 and running gives the error,
AttributeError: 'module' object has no attribute 'rdpcap'
Also comment out line 4 and you get,
AttributeError: 'module' object has no attribute 'send'
Curously, this code fails when invoked with ''python '', but it works as expected when I manually enter each command into the Python shell. I have observed this behaviour on three fresh Python installs - two in Ubuntu, and one in Windows. Can anyone else see the cause of this error?

You need to import Scapy into the global namespace.
From the Scapy module documentation -
Note: In Scapy v2 use from scapy.all import * instead of from scapy import *.
Also found in "Using Scapy to build your own tools".
So your code should be -
from scapy.all import *
dg = IP()
pcap = rdpcap("../tst/Http.cap")
send(IP())

Related

module object has no attribute parse_spec

Environment:-
OS : Ubuntu20.04
Python:2.7.18
Problem:-
I have gerrit trigger plugin installed in jenkins., while building my patch-set it always fails with below error
gbp parse spec failed. 'module' object has no attribute 'parse_spec'
I have already installed git-buildpackage-rpm package still getting the same error.

AttributeError: module 'IPython.core' has no attribute 'shadowns'

I'm running these lines
import dill
dill.load_session("session2.pkl")
and getting the error AttributeError: module 'IPython.core' has no attribute 'shadowns'.
I've saved this session on Google Colab Notebooks. How can I get rid of the error?
I used the simple workaround:
import IPython
IPython.core.shadowns = 1
For some extra packages missing like google or google.colab, I used
%%bash
mkdir google/colab
touch google/colab/__init__.py

How to solve AttributeError: module 'serial' has no attribute 'Serial' in pyserial?

I have a Windows 10 with Python 3.7.4 and I use Jupyter Notebook. I'm trying to use pySerial to connect to my Arduino by Serial attribute. I tried installing pySerial simply by pip install pyserial and eventually I tried conda install -c conda-forge pyserial too, but when I try to run my code:
import serial
ser = serial.Serial('COM4', 9600)
I get an error message like:
AttributeError Traceback (most recent call last)
<ipython-input-7-413d0d9dabe7> in <module>
2 import serial
3 import time
----> 4 ser = serial.Serial('COM4', 9600)
5
6 # Your Account Sid and Auth Token from twilio.com/console
AttributeError: module 'serial' has no attribute 'Serial'
Also, I tried
import serial
serial.__file__
And I got 'C:\Users\lippe\Anaconda3\lib\site-packages\serial\__init__.py' as output.
I also tried dir(serial) and I can't see the Serial attribute in the output, so I think it's basically not installed and I don't know why.
I tried digging the internet but I still can't find a solution.
Make sure you're importing the right serial. After installing pyserial with pip, you can use the __file__ attribute to check that it's the one I expect like so:
>>> import serial
>>> serial.__file__
'/usr/local/lib/python3.7/site-packages/serial/__init__.py'
Other answers suggest it might work to import the class directly with
from serial import Serial
But I'm not sure why this would matter if you're importing the latest published on pypi.

Eclipse PyDev AttributeError: 'module' object has no attribute

I am trying to connect to the shopify api but am having difficulty connecting when using Eclipse+PyDev. When connection via python in a bash shell the same commands work OK
to install:
pip3 install --upgrade ShopifyAPI
shopify.py (my code)
import shopify
shop_url = "https://APIKEY:PASSWORD#mystore.myshopify.com/admin/products.json
shopify.ShopifyResource.set_site(shop_url)
The reference to shopify.ShopifyResouce.. throws the following in PyDev:
AttributeError: 'module' object has no attribute 'ShopifyResource'
I think it may be due to relative imports in the shopify module (the same code works fine in a terminal).
In shopify.py: (shopify API)
from shopify.resources import *
in shopify.resources: (shopify API)
from ..base import ShopifyResource
When I run
from shopify.base import ShopifyResource
ShopifyResource.set_site(shop_url)
I get ImportError: No module named 'shopify.base'; 'shopify' is not a package
Any ides how I can fix this?
The problem might be you created a shopify.py file in your IDE rename that file and that error will be solved

PyDev Eclypse serial.tools library

I need to import serial library in my python project that uses PyQt to build user inteface.
To list all avcailable serial ports I tried to use this command:
import serial
...
def findComPorts(self):
list=serial.tools.list_ports_osx.comports()
port=serial.Serial('...',baudrate=38400)`
but eclipse shows the error: Undefined variable from import: tools
I also tried:
from serial import tools
...
def findComPorts(self):
list=tools.list_ports_osx.comports()
port=serial.Serial('...',baudrate=38400)
but now the error at runtime is: AttributeError: 'module' object has no attribute 'list_ports_osx'
I'm running Eclypse Kepler, Python 2.7, pySerial 2.7 installed via macports

Categories