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:
- 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')
- Fix report column assignment:
report_columns.CampaignPerformanceReportColumn.extend([
'TimePeriod','AccountName','AccountId','CampaignId',
'CampaignName','CampaignType','FinalUrlSuffix','Impressions',
'Clicks','Spend','Conversions'
- 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