How to fix 'print("%s:" % h, end=" ", file=self._fp)' SyntaxError: invalid syntax in python2.7
How to fix 'print("%s:" % h, end=" ", file=self._fp)' SyntaxError: invalid syntax in python2.7
我尝试使用 python 2.7 连接 Google Analytics Reporting API v4。
当我使用这个时:
from googleapiclient.discovery import build
from oauth2client.service_account import ServiceAccountCredentials
error messege :
raceback (most recent call last):
File "C:\Users\Katrina\PycharmProjects\inventory\HelloAnalytics.py", line 4, in <module>
from googleapiclient.discovery import build
File "C:\Python27\lib\googleapiclient\discovery.py", line 52, in <module>
import httplib2
File "C:\Python27\lib\httplib2\__init__.py", line 475
print("%s:" % h, end=" ", file=self._fp)
^
SyntaxError: invalid syntax
我也试过
from apiclient.discovery import build
改为 googleapiclient
并得到了同样的错误。
运行 Python 2.7.13,点 19.1.1
https://developers.google.com/analytics/devguides/reporting/core/v4/quickstart/service-py
Hello Analytics Reporting API v4; Python quickstart for service accounts 快速入门适用于 Python 3
这是因为Google API python client library支持
Python 3.4, 3.5, 3.6 and 3.7 are fully supported and tested. This library may work on later versions of 3, but we do not currently run tests against those versions
您需要升级 python 版本才能使用它。
话虽如此,该库确实声明 2.7 刚刚被弃用,所以我想知道是否应该删除此说明,或者实际上是否有一种方法可以让您更改快速启动以“使其工作”。 (注issue on form about the 2.7 deprecation)
问题表中的注释
Python 2.7 is deprecated, but we intend to drop support for Python 2.7 on January 1, 2020.
The stack trace points to an incompatibility in httplib2. httplib2
started releasing py3 wheels on PyPI a few months ago. (starting with
0.12.3)
The python2 version appears to be available in the .tar.gz. If they
install from the tarfile or pin an older version of httplib2 the
library should still work with Python 2.7.
我尝试使用 python 2.7 连接 Google Analytics Reporting API v4。
当我使用这个时:
from googleapiclient.discovery import build
from oauth2client.service_account import ServiceAccountCredentials
error messege :
raceback (most recent call last):
File "C:\Users\Katrina\PycharmProjects\inventory\HelloAnalytics.py", line 4, in <module>
from googleapiclient.discovery import build
File "C:\Python27\lib\googleapiclient\discovery.py", line 52, in <module>
import httplib2
File "C:\Python27\lib\httplib2\__init__.py", line 475
print("%s:" % h, end=" ", file=self._fp)
^
SyntaxError: invalid syntax
我也试过
from apiclient.discovery import build
改为 googleapiclient 并得到了同样的错误。
运行 Python 2.7.13,点 19.1.1
https://developers.google.com/analytics/devguides/reporting/core/v4/quickstart/service-py
Hello Analytics Reporting API v4; Python quickstart for service accounts 快速入门适用于 Python 3
这是因为Google API python client library支持
Python 3.4, 3.5, 3.6 and 3.7 are fully supported and tested. This library may work on later versions of 3, but we do not currently run tests against those versions
您需要升级 python 版本才能使用它。
话虽如此,该库确实声明 2.7 刚刚被弃用,所以我想知道是否应该删除此说明,或者实际上是否有一种方法可以让您更改快速启动以“使其工作”。 (注issue on form about the 2.7 deprecation)
问题表中的注释
Python 2.7 is deprecated, but we intend to drop support for Python 2.7 on January 1, 2020.
The stack trace points to an incompatibility in httplib2. httplib2 started releasing py3 wheels on PyPI a few months ago. (starting with 0.12.3)
The python2 version appears to be available in the .tar.gz. If they install from the tarfile or pin an older version of httplib2 the library should still work with Python 2.7.