我在Google应用引擎上使用Python。我正在记录错误和信息级别消息。根据文档,我应该在Google App引擎日志中看到消息,但是没有可见的消息。我的代码如下,日志输出如下。请指出,为什么我没有在Google应用引擎日志中看到消息。该代码是Photohunt服务的示例,我正在尝试修改它。
我的代码:
def post(self):
"""Exposed as `POST /api/photos`.
Takes the following payload in the request body. Payload represents a
Photo that should be created.
{
'id':0,
'ownerUserId':0,
'ownerDisplayName':'',
'ownerProfileUrl':'',
'ownerProfilePhoto':'',
'themeId':0,
'themeDisplayName':'',
'numVotes':0,
'voted':false, // Whether or not the current user has voted on this.
'created':0,
'fullsizeUrl':'',
'thumbnailUrl':'',
'voteCtaUrl':'', // URL for Vote interactive post button.
'photoContentUrl':'' // URL for Google crawler to hit to get info.
}
Returns the following JSON response representing the created Photo.
{
'id':0,
'ownerUserId':0,
'ownerDisplayName':'',
'ownerProfileUrl':'',
'ownerProfilePhoto':'',
'themeId':0,
'themeDisplayName':'',
'numVotes':0,
'voted':false, // Whether or not the current user has voted on this.
'created':0,
'fullsizeUrl':'',
'thumbnailUrl':'',
'voteCtaUrl':'', // URL for Vote interactive post button.
'photoContentUrl':'' // URL for Google crawler to hit to get info.
}
Issues the following errors along with corresponding HTTP response codes:
400: 'Bad Request' if the request is missing image data.
401: 'Unauthorized request' (if certain parameters are present in the
request)
401: 'Access token expired' (there is a logged in user, but he doesn't
have a refresh token and his access token is expiring in less than
100 seconds, get a new token and retry)
500: 'Error while writing app activity: ' + error from client library.
"""
try:
user = self.get_user_from_session()
current_theme = model.Theme.get_current_theme()
//mthemeId = self.request.get('themeId')
console.log("Check not working or working. Please work")
logger.debug("Writing photo x" )
mthemeId = self.request.get('themeId')
logging.info("Error while writing app activity: %s", mthemeId)
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
logging.debug("Debug info "+mthemeId)
current_theme = self.request.get('themeId')
current_theme = model.Theme.all().filter('theme_id =', long(mthemeId))
if current_theme:
uploads = self.get_uploads('image')
blob_info = uploads[0]
photo = model.Photo(owner_user_id=user.key().id(),
owner_display_name=user.google_display_name,
owner_profile_photo=user.google_public_profile_photo_url,
owner_profile_url=user.google_public_profile_url,
theme_id=current_theme.key().id(),
theme_display_name=current_theme.display_name,
created=datetime.datetime.now(),
num_votes=0,
image_blob_key=blob_info.key())
photo.put()
try:
result = self.add_photo_to_google_plus_activity(user, photo,mthemeId)
except apiclient.errors.HttpError as e:
logging.error("Error while writing app activity: %s", str(e))
self.send_success(photo)
else:
logging.error("Error while writing app activity: %s", mthemeId)
self.send_error(404, "Current theme not there")
except UserNotAuthorizedException as e:
self.send_error(401, e.msg)
日志 2014-06-06 20:17:04.620 / api /照片404 21ms 0kb PhotoHunt Agent模块=默认版本= 1 0.1.0.30 - - [06 / Jun / 2014:07:47:04 -0700]“POST / api / photos HTTP / 1.1”404 102 - “PhotoHunt Agent”“my-moments.appspot.com” ms = 21 cpu_ms = 0 cpm_usd = 0.000011 app_engine_release = 1.9.5 instance = 00c61b117cfb67f2ae092dbf7270939f50631e97 我2014-06-06 20:17:04.610 make:得到了类型 我2014-06-06 20:17:04.611 验证:获得类型
Post中没有使用Logging.debug或Logging.error编写脚本的消息?我怎样才能看到这些消息。文档说他们应该在日志中可用,但我没有看到。任何帮助/指针真的很感激。
答案 0 :(得分:1)
正在记录的是/api/photos
的404,因此您对该网址的网址映射不正确或缺失。
此外,您将收到此代码的500错误。 console.log("Check not working or working. Please work")
是javascript语法,而不是Python。 logger.debug("Writing photo x" )
会抛出异常,因为您尚未声明logger
。那应该是logging.debug
。
并确保您拥有import logging