Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x Google Adwords流量估计器服务和Python_Python 3.x_Google Ads Api_Adwords Api V201109 - Fatal编程技术网

Python 3.x Google Adwords流量估计器服务和Python

Python 3.x Google Adwords流量估计器服务和Python,python-3.x,google-ads-api,adwords-api-v201109,Python 3.x,Google Ads Api,Adwords Api V201109,我下载了一个代码示例,用于查找特定的关键字并提取一些指标。我注意到很多GoogleAdWordsAPI示例都与Python3.x兼容,所以我想知道这是否有问题?请参见下面的代码示例: from googleads import adwords def main(client): # Initialize appropriate service. traffic_estimator_service = client.GetService( 'TrafficEstimator

我下载了一个代码示例,用于查找特定的关键字并提取一些指标。我注意到很多GoogleAdWordsAPI示例都与Python3.x兼容,所以我想知道这是否有问题?请参见下面的代码示例:

from googleads import adwords


def main(client):
  # Initialize appropriate service.
  traffic_estimator_service = client.GetService(
      'TrafficEstimatorService', version='v201609')

  # Construct selector object and retrieve traffic estimates.
  keywords = [
      {'text': 'mars cruise', 'matchType': 'BROAD'},
      {'text': 'cheap cruise', 'matchType': 'PHRASE'},
      {'text': 'cruise', 'matchType': 'EXACT'}
  ]
  negative_keywords = [
      {'text': 'moon walk', 'matchType': 'BROAD'}
  ]
  keyword_estimate_requests = []
  for keyword in keywords:
    keyword_estimate_requests.append({
        'keyword': {
            'xsi_type': 'Keyword',
            'matchType': keyword['matchType'],
            'text': keyword['text']
        }
    })

  for keyword in negative_keywords:
    keyword_estimate_requests.append({
        'keyword': {
            'xsi_type': 'Keyword',
            'matchType': keyword['matchType'],
            'text': keyword['text']
        },
        'isNegative': 'true'
    })

  # Create ad group estimate requests.
  adgroup_estimate_requests = [{
      'keywordEstimateRequests': keyword_estimate_requests,
      'maxCpc': {
          'xsi_type': 'Money',
          'microAmount': '1000000'
      }
  }]

  # Create campaign estimate requests.
  campaign_estimate_requests = [{
      'adGroupEstimateRequests': adgroup_estimate_requests,
      'criteria': [
          {
              'xsi_type': 'Location',
              'id': '2840'  # United States.
          },
          {
              'xsi_type': 'Language',
              'id': '1000'  # English.
          }
      ],
  }]

  # Create the selector.
  selector = {
      'campaignEstimateRequests': campaign_estimate_requests,
  }

  # Optional: Request a list of campaign-level estimates segmented by
  # platform.
  selector['platformEstimateRequested'] = True

  # Get traffic estimates.
  estimates = traffic_estimator_service.get(selector)

  campaign_estimate = estimates['campaignEstimates'][0]

  # Display the campaign level estimates segmented by platform.
  if 'platformEstimates' in campaign_estimate:
    platform_template = ('Results for the platform with ID: "%d" and name: '
                         '"%s".')
    for platform_estimate in campaign_estimate['platformEstimates']:
      platform = platform_estimate['platform']
      DisplayEstimate(platform_template % (platform['id'],
                                           platform['platformName']),
                      platform_estimate['minEstimate'],
                      platform_estimate['maxEstimate'])

  # Display the keyword estimates.
  if 'adGroupEstimates' in campaign_estimate:
    ad_group_estimate = campaign_estimate['adGroupEstimates'][0]
    if 'keywordEstimates' in ad_group_estimate:
      keyword_estimates = ad_group_estimate['keywordEstimates']
      keyword_template = ('Results for the keyword with text "%s" and match '
                          'type "%s":')

      keyword_estimates_and_requests = zip(keyword_estimates,
                                           keyword_estimate_requests)

      for keyword_tuple in keyword_estimates_and_requests:
        if keyword_tuple[1].get('isNegative', False):
          continue
        keyword = keyword_tuple[1]['keyword']
        keyword_estimate = keyword_tuple[0]
        DisplayEstimate(keyword_template % (keyword['text'],
                                            keyword['matchType']),
                        keyword_estimate['min'], keyword_estimate['max'])


def _CalculateMean(min_est, max_est):
  if min_est and max_est:
    return (float(min_est) + float(max_est)) / 2.0
  else:
    return None


def _FormatMean(mean):
  if mean:
    return '%.2f' % mean
  else:
    return 'N/A'


def DisplayEstimate(message, min_estimate, max_estimate):
  """Displays mean average cpc, position, clicks, and total cost for estimate.
  Args:
    message: str message to display for the given estimate.
    min_estimate: sudsobject containing a minimum estimate from the
      TrafficEstimatorService response.
    max_estimate: sudsobject containing a maximum estimate from the
      TrafficEstimatorService response.
  """
  # Find the mean of the min and max values.
  mean_avg_cpc = (_CalculateMean(min_estimate['averageCpc']['microAmount'],
                                 max_estimate['averageCpc']['microAmount'])
                  if 'averageCpc' in min_estimate else None)
  mean_avg_pos = (_CalculateMean(min_estimate['averagePosition'],
                                 max_estimate['averagePosition'])
                  if 'averagePosition' in min_estimate else None)
  mean_clicks = _CalculateMean(min_estimate['clicksPerDay'],
                               max_estimate['clicksPerDay'])
  mean_total_cost = _CalculateMean(min_estimate['totalCost']['microAmount'],
                                   max_estimate['totalCost']['microAmount'])

  print (message)
  print ('Estimated average CPC: %s' % _FormatMean(mean_avg_cpc))
  print ('Estimated ad position: %s' % _FormatMean(mean_avg_pos))
  print ('Estimated daily clicks: %s' % _FormatMean(mean_clicks))
  print ('Estimated daily cost: %s' % _FormatMean(mean_total_cost))


if __name__ == '__main__':
  # Initialize client object.
  adwords_client = adwords.AdWordsClient.LoadFromStorage()

  main(adwords_client)
以下是错误消息:

(Money) not-found
path: "Money", not-found
(Keyword) not-found
path: "Keyword", not-found
(Keyword) not-found
path: "Keyword", not-found
(Keyword) not-found
path: "Keyword", not-found
(Keyword) not-found
path: "Keyword", not-found
(Location) not-found
path: "Location", not-found
(Language) not-found
path: "Language", not-found
<suds.sax.document.Document object at 0x03BF1D10>
Server raised fault in response.
Traceback (most recent call last):
  File "C:\Users\sfroese\AppData\Local\Programs\Python\Python35-32\lib\site-packages\suds\transport\http.py", line 82, in send
    fp = self.u2open(u2request)
  File "C:\Users\sfroese\AppData\Local\Programs\Python\Python35-32\lib\site-packages\suds\transport\http.py", line 132, in u2open
    return url.open(u2request, timeout=tm)
  File "C:\Users\sfroese\AppData\Local\Programs\Python\Python35-32\lib\urllib\request.py", line 472, in open
    response = meth(req, response)
  File "C:\Users\sfroese\AppData\Local\Programs\Python\Python35-32\lib\urllib\request.py", line 582, in http_response
    'http', request, response, code, msg, hdrs)
  File "C:\Users\sfroese\AppData\Local\Programs\Python\Python35-32\lib\urllib\request.py", line 510, in error
    return self._call_chain(*args)
  File "C:\Users\sfroese\AppData\Local\Programs\Python\Python35-32\lib\urllib\request.py", line 444, in _call_chain
    result = func(*args)
  File "C:\Users\sfroese\AppData\Local\Programs\Python\Python35-32\lib\urllib\request.py", line 590, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 500: Internal Server Error

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\sfroese\AppData\Local\Programs\Python\Python35-32\lib\site-packages\suds\client.py", line 613, in send
    reply = self.options.transport.send(request)
  File "C:\Users\sfroese\AppData\Local\Programs\Python\Python35-32\lib\site-packages\suds\transport\http.py", line 94, in send
    raise TransportError(e.msg, e.code, e.fp)
suds.transport.TransportError: Internal Server Error

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\sfroese\AppData\Local\Programs\Python\Python35-32\adwords test - Copy (2).py", line 177, in <module>
    main(adwords_client)
  File "C:\Users\sfroese\AppData\Local\Programs\Python\Python35-32\adwords test - Copy (2).py", line 95, in main
    estimates = traffic_estimator_service.get(selector)
  File "C:\Users\sfroese\AppData\Local\Programs\Python\Python35-32\lib\site-packages\googleads\common.py", line 696, in MakeSoapRequest
    raise e
  File "C:\Users\sfroese\AppData\Local\Programs\Python\Python35-32\lib\site-packages\googleads\common.py", line 692, in MakeSoapRequest
    for arg in args])
  File "C:\Users\sfroese\AppData\Local\Programs\Python\Python35-32\lib\site-packages\suds\client.py", line 521, in __call__
    return client.invoke(args, kwargs)
  File "C:\Users\sfroese\AppData\Local\Programs\Python\Python35-32\lib\site-packages\suds\client.py", line 581, in invoke
    result = self.send(soapenv)
  File "C:\Users\sfroese\AppData\Local\Programs\Python\Python35-32\lib\site-packages\suds\client.py", line 619, in send
    description=tostr(e), original_soapenv=original_soapenv)
  File "C:\Users\sfroese\AppData\Local\Programs\Python\Python35-32\lib\site-packages\suds\client.py", line 670, in process_reply
    raise WebFault(fault, replyroot)
suds.WebFault: Server raised fault: '[AuthenticationError.CLIENT_CUSTOMER_ID_IS_REQUIRED @ ; trigger:'<null>']'
(钱)找不到
路径:“金钱”,未找到
(关键字)未找到
路径:“关键字”,未找到
(关键字)未找到
路径:“关键字”,未找到
(关键字)未找到
路径:“关键字”,未找到
(关键字)未找到
路径:“关键字”,未找到
(位置)未找到
路径:“位置”,未找到
(语言)找不到
路径:“语言”,未找到
服务器在响应中引发了错误。
回溯(最近一次呼叫最后一次):
文件“C:\Users\sfroese\AppData\Local\Programs\Python\Python35-32\lib\site packages\suds\transport\http.py”,第82行,在send中
fp=self.u2open(u2request)
文件“C:\Users\sfroese\AppData\Local\Programs\Python\Python35-32\lib\site packages\suds\transport\http.py”,第132行,在u2open中
返回url.open(u2request,timeout=tm)
文件“C:\Users\sfroese\AppData\Local\Programs\Python\Python35-32\lib\urllib\request.py”,第472行,打开
响应=方法(请求,响应)
文件“C:\Users\sfroese\AppData\Local\Programs\Python\Python35-32\lib\urllib\request.py”,第582行,在http\U响应中
“http”、请求、响应、代码、消息、hdrs)
文件“C:\Users\sfroese\AppData\Local\Programs\Python\Python35-32\lib\urllib\request.py”第510行出错
返回自我。调用链(*args)
文件“C:\Users\sfroese\AppData\Local\Programs\Python\Python35-32\lib\urllib\request.py”,第444行,在调用链中
结果=func(*args)
文件“C:\Users\sfroese\AppData\Local\Programs\Python\Python35-32\lib\urllib\request.py”,第590行,默认为http\u error\u
raise HTTPError(请求完整的url、代码、消息、hdrs、fp)
urllib.error.HTTPError:HTTP错误500:内部服务器错误
在处理上述异常期间,发生了另一个异常:
回溯(最近一次呼叫最后一次):
文件“C:\Users\sfroese\AppData\Local\Programs\Python\Python35-32\lib\site packages\suds\client.py”,第613行,在send中
reply=self.options.transport.send(请求)
文件“C:\Users\sfroese\AppData\Local\Programs\Python\Python35-32\lib\site packages\suds\transport\http.py”,第94行,在send中
raise TRANSPORT错误(e.msg、e.code、e.fp)
suds.transport.TransportError:内部服务器错误
在处理上述异常期间,发生了另一个异常:
回溯(最近一次呼叫最后一次):
文件“C:\Users\sfroese\AppData\Local\Programs\Python\Python35-32\adwords test-Copy(2.py)”,第177行,在
主(ADU客户端)
文件“C:\Users\sfroese\AppData\Local\Programs\Python\Python35-32\adwords test-Copy(2.py)”,第95行,在main中
estimates=流量\估计器\服务.get(选择器)
MakeSoapRequest中第696行的文件“C:\Users\sfroese\AppData\Local\Programs\Python35-32\lib\site packages\googleads\common.py”
提高e
文件“C:\Users\sfroese\AppData\Local\Programs\Python\Python35-32\lib\site packages\googleads\common.py”,第692行,在MakeSoapRequest中
对于args中的arg])
文件“C:\Users\sfroese\AppData\Local\Programs\Python\Python35-32\lib\site packages\suds\client.py”,第521行,在调用中__
返回client.invoke(args、kwargs)
文件“C:\Users\sfroese\AppData\Local\Programs\Python\Python35-32\lib\site packages\suds\client.py”,第581行,在invoke中
结果=self.send(soapenv)
文件“C:\Users\sfroese\AppData\Local\Programs\Python\Python35-32\lib\site packages\suds\client.py”,第619行,在send中
description=tostr(e),original_soapenv=original_soapenv)
文件“C:\Users\sfroese\AppData\Local\Programs\Python\Python35-32\lib\site packages\suds\client.py”,第670行,进程中
升起WebFault(故障,replyroot)
suds.WebFault:服务器引发的错误:“[AuthenticationError.CLIENT\u CUSTOMER\u ID\u是必需的@;触发器:“””

您应该在googleads.yaml文件中设置客户id。您可以从经理帐户获取客户id。转到您的经理帐户并添加客户端,然后从屏幕的正角复制您的id。在googleads.yaml文件中,将该id粘贴到客户id

看起来好像您没有修改.yaml文件?您正在从存储加载,因此您的Adwords API凭据需要位于该文件中。以下是有关未找到邮件的来源的更多信息?肥皂水?有消息吗?我也有同样的。。