ImportError: cannot import name 'http' from 'scapy.layers

Hi,

I am currently on the section - “Extracting Data From a Specific Layer”, and am having difficulties with the scapy module.

My code so far:

#!/usr/bin/env python

import scapy.all as scapy
from scapy.layers import http

load_layers(‘http’)

def sniff(interface):
scapy.sniff(iface=interface, store=False, prn=process_sniffed_packet)

def process_sniffed_packet(packet):
if packet.haslayer(http.HTTPrequest):
print(packet.show())

sniff(“eth0”)

The error on terminal when ran:

ImportError: cannot import name http.

Now, I have already successfully installed the required scapy packages - I have tried troubleshooting this via the official documentation, along with stackoverflow, however getting nowhere fast. The scapy documentation states that it is deprecated.

Can anyone help with this or provide a useful workaround?! I have a university assignment due in on Sunday; this course has been helping massively, however, currently stuck on this section!

Were you ever able to figure this out? I’m having the exact same issue and all of the information I have found online is not working. I get the cannot import name http as well.

1 Like

Can you try this and please let me know if it helps? --> from scapy.layers.http import *


Was never able to figure it out. Asked one of my lecturers at uni and they advised to not bother using the scapy module! Tried all the workaround on stackoverflow, etc, but none worked.

Hi Manimiddle,

Please update Kali repo, and install scapy and scapy-http modules:
apt-get update
pip install scapy==2.4.2
pip install scapy-http==1.8.2