You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PyCharm调试器下Requests库无异常返回错误的原因与抑制方法

Why This Happens & How to Fix It

Cause

These ignored exceptions are a known compatibility quirk between older PyCharm debuggers (like your 2018.1 version) and Python 3.6's generator garbage collection behavior—especially noticeable in multi-threaded projects.

Here's the breakdown:

  • When generators (such as those from urllib.parse.urlsplit and requests.utils.iter_slices) go out of scope and get garbage-collected, the PyCharm debugger's instrumentation hooks interfere with the cleanup process.
  • The exceptions are thrown during this teardown but immediately marked as "ignored" by Python, which is why they don't break your code or affect functionality. The SystemError: error return without exception set is a side effect of the debugger conflicting with Python's internal exception handling during generator cleanup.

This isn't a problem with your code—it's a tooling issue that pops up consistently in older PyCharm/Python 3.6 combinations.

Solutions to Suppress Log Pollution

1. Upgrade PyCharm (Best Fix)

The simplest and most reliable fix is to upgrade your PyCharm to a newer version (2020.1 or later). JetBrains addressed this debugger-related generator cleanup bug in subsequent releases, so updating should eliminate the logged exceptions entirely.

2. Update Python & Requests

Python 3.6 reached end-of-life in December 2021, and newer versions (3.7+) have improvements to generator garbage collection and exception handling that avoid this conflict. Additionally, upgrading Requests to a more recent version (e.g., 2.25.x or later) replaces the generator patterns that trigger the issue with safer alternatives.

3. Disable Debugger's Runtime Type Collection

If upgrading isn't an option right now, try turning off a debugger feature that's often the culprit:

  • Go to File > Settings > Build, Execution, Deployment > Debugger > Data Views
  • Uncheck the box labeled Collect run-time types information
  • Restart your debugger. This reduces the debugger's intrusiveness and can stop the exceptions from being logged.

4. Filter Ignored Exceptions in PyCharm

You can tell PyCharm to stop tracking these specific ignored exceptions:

  • Go to Run > View Breakpoints (or press Ctrl+Shift+F8)
  • Switch to the Python Exception Breakpoints tab
  • Look for SystemError and the exceptions linked to urllib.parse/requests.utils
  • Uncheck the box next to them, or click the - button to remove them from the debugger's tracked exceptions list.

Alternatively, you can add a custom exception hook in your code to filter out these specific ignored exceptions (use cautiously, as it suppresses them globally):

import sys

original_excepthook = sys.excepthook

def custom_excepthook(exc_type, exc_value, exc_traceback):
    # Filter out the problematic ignored exceptions
    if (exc_type is SystemError and "error return without exception set" in str(exc_value)) or \
       (exc_type is Exception and "generator object urlsplit" in str(exc_value)):
        return
    original_excepthook(exc_type, exc_value, exc_traceback)

sys.excepthook = custom_excepthook

内容的提问来源于stack exchange,提问作者CodeSamurai777

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 03:59:58