how to resolve ConnectionResetError(104, Connection reset by peer) when requesting for Microsoft Ads report using python library

Derek Poh 0 Reputation points
2025-11-07T02:09:19.7333333+00:00

I keep getting the error
('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))

when trying to download campaign performance report using the Python SDK.
May I know how I can resolve this error?

Attached is the python script (in txt extension) get_report.txt.
Please let me know what other information I need to provide.

Microsoft Advertising API
Microsoft Advertising API
A Microsoft API that provides programmatic access to Microsoft Advertising to manage large campaigns or to integrate your marketing with other in-house systems.
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. MS Advertising - Dagmara 395 Reputation points Microsoft External Staff Moderator
    2025-11-07T07:52:14.64+00:00

    Hi Derek Poh,

    Thank you for reaching out to the Microsoft Advertising Learn Q&A Platform!

    The error ConnectionResetError(104, 'Connection reset by peer') is a low-level network error that typically means the server forcibly closed the connection. In the context of the Bing Ads Python SDK, this is most often caused by:

    • Missing or invalid authentication: Your script sets authentication=None, which means no valid OAuth token is being passed. This is the most likely cause. You must initialize and authenticate using a valid OAuthWebAuthCodeGrant or similar object.
    • Improper report request formatting: Your use of .append([...]) on report_columns.CampaignPerformanceReportColumn is incorrect. Try .extend([...]) to add multiple columns.
    • Trailing comma in assignment: AccountId=authorization_data.account_id, creates a tuple, not a variable. Try removing the comma.
    • Large report or timeout: If the report is too large or takes too long, the server may reset the connection. Try reducing the report scope or increasing the timeout.
    • Network/firewall issues: If you're behind a proxy or firewall, it may interfere with the connection. Try running the script from a different network or environment.

    What You Should Do:

    1. Fix authentication setup:

    from bingads.authorization import OAuthWebAuthCodeGrant

    authentication = OAuthWebAuthCodeGrant( client_id='your-client-id', client_secret='your-client-secret', redirection_uri='your-redirect-uri' ) authorization_data.authentication = authentication authentication.request_access_and_refresh_tokens('your-auth-code')

    1. Fix report column assignment:

    report_columns.CampaignPerformanceReportColumn.extend([

     'TimePeriod','AccountName','AccountId','CampaignId',

    'CampaignName','CampaignType','FinalUrlSuffix','Impressions',

    'Clicks','Spend','Conversions'

    1. Remove trailing comma:

    AccountId = authorization_data.account_id

    Get Started Using Python with Bing Ads API - Microsoft Advertising API | Microsoft Learn
    CampaignPerformanceReportRequest Data Object - Reporting - Microsoft Advertising API | Microsoft Learn

    I hope the information provided here will at least partly answer your question. For us to make sure that we are able to address the issue, I'll be sending a private message on your inbox, please check your private message for further assistance.

    Our support teams are happy to discuss your account in more detail via phone, chat or email to provide review assistance, please see our support page to reach out!

    Kind regards, 

    Dagmara | Microsoft Advertising Support Specialist | 800-518-5689

    0 comments No comments

  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  3. Derek Poh 0 Reputation points
    2025-11-10T01:43:01.7233333+00:00

    debug.txtHi Dagmara

    Thank you for responding.

    I have fixed the report column assignment and removed the trailing comma.
    I am using the auth_helper.py for the authentication part, do I need to do this step 'Fix authentication setup'?

    I tried with the sample project (BingAds-Python-SDK\examples\v13\report_requests.py) and I got this output message

    Loading the web service client proxies...

    -----

    Awaiting download_report...

    ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))

    The tracking id is '6dcd91db-a2a8-4bff-9d51-8a5354deac98'

    Attached is the debug output for auth_helper.py .


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.