IO Errno 13权限被拒绝

时间:2018-12-14 06:38:54

标签: python

有一个脚本,在该脚本中,我试图从一个站点提取两个不同的流并将其放入2个不同的文件中。不幸的是,仅生成了1个输出文件,并且我收到了错误消息:

正在清理数据..._ LiveChat_agents

Traceback (most recent call last): File "C:\Python_Prog\Customer_Care\LiveChat+Chats.py", line 45, in <module> with open(messages, 'w') as outfile: IOError: [Errno 13] Permission denied: 'LiveChat_agents14-12-2018.json'

这是我的脚本: *从azure.storage.blob导入BlockBlobService

from azure.storage.blob import ContentSettings
import requests
import re
import os
import json
import datetime
import logging
#authenitcation service-to-service-to-serv
block_blob_service = BlockBlobService(account_name='datalake', account_key='XXXXXX'
now = datetime.datetime.now()
today = now.strftime("%d-%m-%Y")
logs = 'C:\\Python_Execution\\Log\\'
os.chdir(logs)
if not os.path.exists(today):
    os.makedirs(today)
file_out = "C:\\Python_Execution\\Temp"
os.chdir(file_out)
#authenticate
#url = 'https://api.livechatinc.com/v2/chats'
headers = {'X-API-Version': '2',}
response_agents = requests.get('https://api.livechatinc.com/agents', headers=headers, auth=('jdoe@whatever.com', '000'))
#print(response_agents.text)
response_agents_toclean = response_agents.text
response_agents_clean = response_agents_toclean.encode('utf-8')
logging.info('Writing data to local file')
response_agents_final = json.loads(response_agents_clean)
messages = 'LiveChat_agents' + today +'.json'
print('Cleaning data..._LiveChat_agents')
response_agents_final = json.loads(response_agents_clean)
with open(messages, 'w') as outfile:
   json.dump(response_agents_final, outfile)

#extract Chats
response_chats = requests.get('https://api.livechatinc.com/chats', headers=headers, auth=('jdoe@whatever.com', '000'))
#print(response_chats.text)
response_chats_toclean = response_chats.text
response_chats_clean = response_chats_toclean.encode('utf-8')
logging.info('Writing data to local file')
response_chats_final = json.loads(response_chats_clean)
messages = 'LiveChat_chats' + today +'.json'
print('Cleaning data...LiveChat_chats')
response_chats_final = json.loads(response_chats_clean)
with open(messages, 'w') as outfile:
   json.dump(response_chats_final, outfile)

   print('Uploading to blob storage...')
logging.info('Uploading to blob storage')
blob_container = 'landing-livechat'
#Upload the CSV file to Azure cloud
block_blob_service.create_blob_from_path(
    blob_container,
    messages,
    file_out + '\\' + messages,
    content_settings=ContentSettings(content_type='application/JSON')
            )
# Check the list of blob
generator = block_blob_service.list_blobs(blob_container)
for blob in generator:
    print(blob.name)
logging.info('Upload completed successfully')
print('Deleting temp file...')
logging.info('Deleting temp file')
os.chdir(file_out)
os.remove(messages)
logging.info('Completed Sucessfully!')*

感谢您的帮助。 格拉西亚斯 M

0 个答案:

没有答案