When I type "python" to get to the python command line and execute this script it works perfectly and does exactly what I need it to do:
import json
import datetime
dictstr = {'FeedbackScore': '884', 'IDVerified': 'false', 'eBayGoodStanding': 'true', 'AboutMePage': 'false', 'UserSubscription': ['FileExchange'], 'UserIDChanged': 'false', 'PayPalAccountType': 'Business', 'PositiveFeedbackPercent': '100.0', 'Email': 'xxxxxxxxx', 'EIASToken': 'xxxxxxxxxxxxxxx', 'PayPalAccountStatus': 'Active', 'UniquePositiveFeedbackCount': '66', 'UniqueNeutralFeedbackCount': '0', 'SellerInfo': {'CheckoutEnabled': 'true', 'TransactionPercent': '69.0', 'StoreOwner': 'false', 'AllowPaymentEdit': 'false', 'RecoupmentPolicyConsent': None, 'PaymentMethod': 'PayPal', 'GoodStanding': 'true', 'SafePaymentExempt': 'true', 'SellerGuaranteeLevel': 'NotEligible', 'LiveAuctionAuthorized': 'false', 'MerchandizingPref': 'OptIn', 'CIPBankAccountStored': 'false', 'QualifiesForB2BVAT': 'false', 'SchedulingInfo': {'MaxScheduledMinutes': '30240', 'MaxScheduledItems': '3000', 'MinScheduledMinutes': '0'}, 'CharityRegistered': 'false'}, 'UserIDLastChanged': datetime.datetime(2014, 8, 6, 0, 37, 37), 'EnterpriseSeller': 'false', 'Status': 'Confirmed', 'PayPalAccountLevel': 'Verified', 'UserID': 'xxxxxxxxxxxx', 'eBayWikiReadOnly': 'false', 'FeedbackRatingStar': 'Purple', 'UniqueNegativeFeedbackCount': '0', 'VATStatus': 'NoVATTax', 'MotorsDealer': 'false', 'RegistrationDate': datetime.datetime(2003, 1, 12, 0, 21, 42), 'BusinessRole': 'FullMarketPlaceParticipant', 'Site': 'US', 'EBaySubscription': 'FileExchange', 'FeedbackPrivate': 'false', 'NewUser': 'false'}
f = open('json_output.txt','w')
dump_file = json.dumps(dictstr, indent=4, default=str)
f.write(dump_file)
f.close()
However when I run this as a script the content of my output file are all on one line:
import json
import datetime
import ebaysdk
from ebaysdk.trading import Connection as Trading
def getUser():
api = Trading(config_file='ebay.yaml')
f = open('json_output.txt','w')
api.execute('GetUser', {'UserID': 'xxxxxxxxx'})
dictstr = "%s" % api.response.reply.User
print dictstr
dump_file = json.dumps(dictstr, indent=4, default=str)
f.write(dump_file)
f.close()
if __name__ == "__main__":
getUser()
the file is all on one line, like the original declaration of the dictionary.
I'm using the contents of stdout in the non-working example to populate the dictstr variable in the working example. I am doing this because I want to make sure I'm using the exact same data.
Any of you experts know what I'm doing wrong here?