本文介绍了SSIS执行过程任务,将Python脚本转换为具有OAuth2的API-访问被拒绝的文件带有保存的令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的问题,不知道要进一步检查。



情况摘要:




  • 以管理员身份在Windows Server 2016上工作,因此应该不会有任何访问问题

  • 开发了一些Python脚本,使用,从Google Analytics(分析)获取数据采取了


    一切正常!


    I have strange problem and don't know what to check further.

    Summary of the situation:

    • working on the Windows Server 2016 as administrator, so should not have any access problems
    • developed some Python script for getting data from Google Analytics using , as basis took this example (but getting data only from one account and only for one time interval)
    • script successfully works: withing the first time code of API execution opens GA Web Site in browser, requests for authorization and approves API connection, creates analytics.dat file with store connection token inside
    • right after that all the next script executions successfully get information from GA and save it in file
    • but when I trying to add the same script execution into SSIS Package as Execute Process Task step and executing that step (Visual Studio is opened under the same administrator account withing the same active windows session) - it requests again authorization on the web-site, after successful authorization I see The authentication flow has completed message in browser, close it, but getting the error of Python script's execution:

    • I tried to delete that file analytics.dat - but after that getting the same error.
    • I executed Python script by .bat file with the command inside C:\Python27\python.exe C:\BI\API\Python_GoogleAnalytics_Reporting\v3_api_analytics\google_analytics_api_v3_10krows_nosampling_multiple_profiles.py. Execution of the .bat itselft works fine, but execution of the same .bat from SSIS Package as Execute Process Task step - returns the errors above
    • Also, had the same problem before with Bing Ads API. But there I temporary fixed that by commented out line in the code with re-writing of updated token information to the file: in Bing Ads it is valid long time before expiring. But in the GA API that token in file expires after 1 hour and after that that file need to be overwritten.
    • also, I tried to add into scripts some prints to show under which service account script executes from SSIS package in Visual Studio (using print(os.getlogin())) - but as expected it shows the same administrator account under which I am working on the Server...

    So, I don't understand, why I am getting such Access denied to the file with saved token problem...In the properties of the file the owner - is the same Windows Administrator account, under whose session I am opening Visual Studio for execution of the step in DTSX package.

    Could you help me to find the problem, please?

    解决方案

    I found the problem. And it was related with the properties of Execute Process Task step of SSIS Package...

    As I noticed above, I executed Python script by .bat file with the command inside:C:\Python27\python.exe C:\BI\API\Python_GoogleAnalytics_Reporting\v3_api_analytics\google_analytics_api_v3_10krows_nosampling_multiple_profiles.py.Execution of the .bat itself worked fine, but execution of the same .bat from SSIS Package as Execute Process Task step - returns the errors above.

    In the logs of errors in the beginning we see:

    What says initially, that there is no file analytics.dat in the working folder of script.But I expected, that script executes in the same folder where it is located and there already had existed file C:\BI\API\Python_GoogleAnalytics_Reporting\v3_api_analytics\analytics.dat

    But then I noticed, that on the first place in that message (I marked it as bold) is working folder of the external script execution, script starts in the SSIS folder.

    I found, that when the process is launched from SSIS, it's not being run from the same folder as the executable .bat file located.What is different from the direct .bat file execution.

    So, it is necessary additionally specify working folder property of Execute Process Task step of SSIS Package.

    I set such property value:

    Working directory: C:\BI\API\Python_GoogleAnalytics_Reporting\v3_api_analytics\

    And everything works fine!

    这篇关于SSIS执行过程任务,将Python脚本转换为具有OAuth2的API-访问被拒绝的文件带有保存的令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 07:21