这是indexloc提供的服务,不要输入任何密码
Skip to content
This repository was archived by the owner on Jan 24, 2023. It is now read-only.
This repository was archived by the owner on Jan 24, 2023. It is now read-only.

can't pass the google analytics traffic through http proxy #14

@mostafaghadimi

Description

@mostafaghadimi

I have read the following links and try them, but they didn't work properly:

My problem is different from the other questions, since I am using ServiceAccountCredentials method from oauth2client.service_account package. The authentication to the API key is done with json file. (also ServiceAccountCredentials.from_json_keyfile_name method). Whenever I want to request to the google service, I want to pass it from http proxy server, unfortunately there isn't any rich documentation for this purpose on the web (or maybe I couldn't find them).

ga_base_config.yml

PROXY:
  proxy_user: '<proxy_user>'
  proxy_pass: '<proxy_password>'
  proxy_host: '<proxy_host>'
  proxy_port: <port_no>

main.py

class GA:
    def __init__(self, root_dir):
        with open(os.path.join(root_dir, 'config/ga_base_config.yml'), 'r') as yaml_file:
            try:
                self.yaml_file = yaml.safe_load(yaml_file)
                print(self.yaml_file)
            except yaml.YAMLError as exc:
                print(exc)

        self.scopes = self.yaml_file['URL']['scope']
        self.proxy_info = self.yaml_file['PROXY']

        self.key_file_location = os.path.join(root_dir, self.yaml_file['KEY_FILE'])

    def initialize_analytics_reporting(self):
        """Initializes an Analytics Reporting API V4 service object.

        Returns:
          An authorized Analytics Reporting API V4 service object.
        """
        credentials = ServiceAccountCredentials.from_json_keyfile_name(
            self.key_file_location,
            self.scopes,
        )
        proxy = httplib2shim.Http(self.proxy_info)
        credentials.authorize(http=proxy)
        analytics = build(
            'analyticsreporting',
            'v4',
            credentials=credentials,
        )
        return analytics

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions