Skip to content
This repository has been archived by the owner on Jan 24, 2023. It is now read-only.

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

Open
mostafaghadimi opened this issue Jan 24, 2021 · 0 comments
Open

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

mostafaghadimi opened this issue Jan 24, 2021 · 0 comments

Comments

@mostafaghadimi
Copy link

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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant