【问题标题】:youtube api request on azure doesn't workazure 上的 youtube api 请求不起作用
【发布时间】:2017-08-14 16:20:58
【问题描述】:

我在 Microsoft Azure 上有一个小型 python/flask 应用程序,这里:https://sdtflask.azurewebsites.net/#!/

这是在我的本地机器上开发的,然后推送到 GitHub 并自动部署到 Azure。两端一切正常,除了应用程序的一小部分,这是对 youtube API 的 http 请求,用于从 youtube 频道检索一些信息。

这在我的本地机器上运行良好,但是在 Azure 上尝试时却不行。

两端代码相同:

import requests
from flask_restful import Resource

class GetChannelList(Resource):
    def get(self):
        try:
            url = "https://content.googleapis.com/youtube/v3/search?key=AIzaSyCxd3KGNNiZy-omyDH7U8Lr3zGQD6ZO448&channelId=UCvS6-K6Ydmb4gH-kim3AmjA&part=snippet,id&order=date&maxResults=50"
            r = requests.get(url).json()
            # r.raise_for_status()
            return r
        except Exception as e:
            print(str(e))
            return {'message': 'something went wrong'}

然后我有以下内容:

from flask import Flask
from flask_restful import Api
from api.get_channel_list import GetChannelList
app = Flask(__name__)

api = Api(app)

api.add_resource(GetChannelList, "/api/get_channel_list")

import FlaskWebProject1.views

然后在我的 Angular 控制器上执行以下操作:

angular.module('sdt')
    .controller('mainCtrl', function($scope, $http){
        $scope.showResults = function(){
            $scope.data = $http.get('api/get_channel_list').then(function(data){
                console.log(data);
                $scope.printTable(data);
            });
          }
            $scope.printTable = function(data){
                $scope.pageToken = data.data.nextPageToken;
                // $scope.fetchMore($scope.pageToken);
                $scope.items = data.data.items;
            }
    });

它在我的本地机器上运行良好:

但是一旦我部署到服务器,它就不会加载任何东西,这就是我在控制台的 JSON 上得到的:

我检查了应用程序流日志,没有显示错误,也没有 python 错误,这让我相信 azure 可能会阻止请求?有人知道会发生什么吗?任何关于我下一步可以做什么的指示将不胜感激。提前致谢

【问题讨论】:

  • 尝试打印确切的异常? sys.exc_info()[0] ?
  • 抛出以下错误:"<class 'requests.exceptions.SSLError'>"@pyjg
  • @pyjg 添加这个作为答案,所以我把它作为正确的答案。

标签: python angularjs azure youtube-data-api


【解决方案1】:

也许Python Requests throwing up SSLError 会帮助你弄清楚为什么会有SSLException 发生

看起来最快的解决方法是设置verify=False。 (取自链接中的答案)

【讨论】:

    猜你喜欢
    • 2015-06-26
    • 1970-01-01
    • 2021-04-20
    • 1970-01-01
    • 2013-02-09
    • 2021-02-15
    • 1970-01-01
    • 1970-01-01
    • 2017-01-15
    相关资源
    最近更新 更多