首页 > 编程问答 >python中使用mitmproxy的http模块出错

python中使用mitmproxy的http模块出错

时间:2024-07-22 08:05:47浏览次数:9  
标签:python scapy curses mitmproxy

我有一个使用 mitmproxy http 函数的代码,它在这里惨败:

def main(stdscr):
    try:
        parser = argparse.ArgumentParser(description='NetSour Network Analyzer')
        parser.add_argument('--proxy', action='store_true', help='Enable HTTPS decryption (BETA)')
        args = parser.parse_args()
        if args.proxy:
            print("WARNING: HTTPS decryption is in BETA. Use at your own risk.")
            from mitmproxy.tools.main import mitmdump
            >>>>mitmdump(['--scripts', __file__, '--set', 'block_global=false'])
            return
        if is_root():
            stdscr.addstr(0, 0, "[+] You are root.")
        else:
            stdscr.addstr(0, 0, "[-] You are not root.")
        stdscr.addstr(1, 0, "[+] Enter the interface name: ")
        curses.echo()
        interface = stdscr.getstr().decode()
        curses.noecho()

        packet_queue = Queue()
        sniff_thread = Thread(target=sniff_packets, args=(packet_queue, interface))
        sniff_thread.daemon = True
        sniff_thread.start()
        
        stdscr.addstr(3, 0, "[+] Starting NetSour...")
        stdscr.refresh()
        time.sleep(1)
        
        display_packets(stdscr, packet_queue)
    except Exception as e:
        print(f"Error in main function: {str(e)}")

返回 return _signature_from_callable(obj, sigcls=cls, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 文件“/usr/lib/python3.11/inspect.py”,第 2447 行,在 _signature_from_callable 中 raise TypeError('{!r} 不是可调用对象'.format(obj)) 类型错误:不是可调用对象 [19:36:20.886] HTTP(S) 代理侦听 *:8080。 启动期间记录错误,退出...

我问 ChatGpt,它说它与一个名为 ColorTables 的未知函数有关,所以我搜索了它,但它什么也没做。


The error message you're encountering is a bit misleading because it doesn't directly point to the root cause within your code snippet. However, the traceback provides valuable clues:

Traceback Analysis

  • TypeError: '...' object is not callable : This usually means you're trying to invoke a function, but the object you're using is not a function.
  • File ".../inspect.py", line 2447, in _signature_from_callable : The error originates deep within Python's introspection library ( inspect ). This library is used to examine the properties of Python objects, including whether something is callable (like a function).

The Issue: mitmdump(['--scripts', __file__, '--set', 'block_global=false'])

The problem lies in how you're attempting to use mitmdump . mitmdump is not a function designed to be called directly within your Python script. It's a command-line utility provided by mitmproxy .

Solution: Subprocess for External Commands

To run mitmdump correctly, you need to treat it as a separate process that your script launches:

import subprocess

def main(stdscr):
    # ... your existing code ...

        if args.proxy:
            print("WARNING: HTTPS decryption is in BETA. Use at your own risk.")
            # Launch mitmdump as a subprocess
            subprocess.Popen(['mitmdump', '--scripts', __file__, '--set', 'block_global=false'])
            return  # Consider if you want your script to continue or wait

        # ... your existing code ...

Explanation:

  1. subprocess.Popen : This function is used to start a new process.
  2. Command List : You pass the command you want to execute as a list:
  3. 'mitmdump' : The name of the mitmdump executable.
  4. '--scripts' , __file__ , ...: Arguments passed to mitmdump.
  5. Subprocess Execution : mitmdump will run as a separate process alongside (or in the background of) your Python script.

Important Considerations:

  • Blocking vs. Non-Blocking : If you want your script to pause until mitmdump finishes, you can use subprocess.call() instead of Popen() . However, this might not be desirable in your case.
  • Communication : If you need to exchange data between your Python script and the running mitmdump process, you'll need to explore inter-process communication mechanisms (e.g., pipes, queues).

Let me know if you have any other questions!

标签:python,scapy,curses,mitmproxy
From: 78776577

相关文章

  • 使用python图像去噪没有获得所需的重建图像
    我是python机器学习的初学者,我正在编写一个程序,使图像变得嘈杂,然后我的程序输出重建的图像。我正在使用加性高斯白噪声并使用前馈神经网络。我的程序显示真实图像、噪声图像和重建图像。这些是我通常得到的结果。有人知道如何解决这样的问题吗?这是我的代码:ap......
  • 使用 pip 22.3.1 和 python 3.11.0 安装 MetaTrader5 错误
    我正在尝试使用pip在Windows上安装MetaTrader5。python--versionPython3.11.0pip--versionpip22.3.1pipinstallMetaTrader5ERROR:CouldnotfindaversionthatsatisfiestherequirementMetaTrader5(fromversions:none)ERROR:Nomatchingdistribu......
  • 在 Python 中溶解线条
    我有一个包含多行的形状文件。我正在寻找一种方法来消除所有的接触线。这在ArcMap中是可能的,但似乎在Python和QGIS中都无法做到:之前:所需的输出:这需要在多行上完成,因此像QGIS合并一样手动执行不是一个选项。在ArcMap中,我曾经使用“溶解”......
  • 一个简单的问题(python、串行通信和arduinos)
    只是一个关于小脚本的快速问题,由于某种原因无法工作我运行了这个脚本:importserialimporttimeimportturtledefserialreading():serialPort=serial.Serial(port="COM5",baudrate=9600,bytesize=8,timeout=2,stopbits=serial.STOPBITS_ONE......
  • 我在 Windows 10 上运行 Python 代码后控制台立​​即关闭
    虽然我在代码末尾使用input(),但在Windows10(IDLE之外)的窗口中输入名称后,控制台仍然立即关闭,并且我看不到结果。我该怎么做才能阻止控制台关闭?#!python3name=input('Enteryourname:')print('Hello'+name)input('pressEntertoexit:')你在代码末尾......
  • 具有未定义嵌套列表深度的嵌套列表的Python注释类型
    [[1,2,3],3,[2,4],5]的类型是list[list[int]|int]但是,如果嵌套列表具有未定义的深度,例如[[[1,2]],2,[1,[3,[3]]]],3,[2,[2]]],那么它会具有什么类型?可以使用递归类型提示来表示任意深度嵌套的列表:fromtypingimportList,Union......
  • 在Spyder(Python 3.6)中导入cv2时出现导入错误
    我已经在Windows操作系统中安装了opencv3.0.0。我已运行该应用程序并已成功将其安装在C:\驱动器中,并且还将cv2.pyd文件复制到C:\Python27\Lib\site-packages中,正如我在几个教程视频中看到的那样在我的Python2.7.5Shell中,即当我键入>>>i......
  • Python + VS Code 调试器:可视化我的程序当前正在执行的源代码中的位置?
    当我使用VSCodePython调试器时:我可以执行我的程序,以便编辑器将我逐行带到源代码中的任何位置(跳转到相关文件/如果尚未打开则将其打开)目前的执行情况是?是的,VSCode的Python调试器可以让你逐行执行代码,并实时显示当前执行的位置。以下是操作方法:1.设置断点:......
  • 如何立即取消使用 Ollama Python 库生成答案的 Asyncio 任务?
    我正在使用Ollama通过OllamaPythonAPI从大型语言模型(LLM)生成答案。我想通过单击停止按钮取消响应生成。问题在于,只有当响应生成已经开始打印时,任务取消才会起作用。如果任务仍在处理并准备打印,则取消不起作用,并且无论如何都会打印响应。更具体地说,即使单击按钮后,此函数......
  • 使用 np.array 索引过滤 Python 列表
    谁能向我解释一下列表self.data如何使用numpy索引数组selec_idx进行索引/过滤?完整的课程可在https://github.com/kaidic/LDAM-DRW/blob/master/imbalance_cifar.pydefgen_imbalanced_data(self,img_num_per_cls):new_data=[]n......