Python doesn't print with import scapy

2019-07-24 18:30发布

问题:

When I enter this code:

print "hhhh"
from scapy.all import sniff
print "bbbb"

this is the output:

C:\Python27\python.exe C:/Users/Tamir/PycharmProjects/SIP/main.py
hhhh
WARNING: No route found for IPv6 destination :: (no default route?)

Process finished with exit code 0

Why doesn't the second print (of "bbbb") work? When I put the import line in a comment, or import another library, it works.

回答1:

sys.stdout is redirected to readline console. It seems not working well with pycharm in this way. Please check: "PYTONPATH\Lib\site-packages\scapy\arch\windows__init__.py"

temporary solution: redirect stdout to the original one

try this:

import sys
print "hhhh"
orig_stdout = sys.stdout
from scapy.all import sniff
sys.stdout =  orig_stdout
print "bbbb"