php引用python出现502,【已解决】python执行出错:HTTPError: HTTP Error 502: Bad Gateway

【已解决】python执行出错:HTTPError: HTTP Error 502: Bad Gateway

【背景】

某此脚本执行,出现错误:LINE 1687 : ERROR    Unknown Error !

Traceback (most recent call last):

File “E:WebServerWordPressto_wphi-baidu-mover_v2hi-baidu-mover_v2011-12-24.py”, line 1685, in

try:

File “E:WebServerWordPressto_wphi-baidu-mover_v2hi-baidu-mover_v2011-12-24.py”, line 1632, in main

gVal[‘statInfoDict’][‘exportedItemIdx’] += 1

File “E:WebServerWordPressto_wphi-baidu-mover_v2hi-baidu-mover_v2011-12-24.py”, line 1351, in exportEntry

calcTimeStart(“translate_post_name”)

File “E:WebServerWordPressto_wphi-baidu-mover_v2hi-baidu-mover_v2011-12-24.py”, line 849, in translateString

trans_req.add_header(‘User-Agent’, “Mozilla/4.0 (compatible;MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)”)

File “E:dev_install_rootPython27liburllib2.py”, line 126, in urlopen

return _opener.open(url, data, timeout)

File “E:dev_install_rootPython27liburllib2.py”, line 400, in open

response = meth(req, response)

File “E:dev_install_rootPython27liburllib2.py”, line 513, in http_response

‘http’, request, response, code, msg, hdrs)

File “E:dev_install_rootPython27liburllib2.py”, line 438, in error

return self._call_chain(*args)

File “E:dev_install_rootPython27liburllib2.py”, line 372, in _call_chain

result = func(*args)

File “E:dev_install_rootPython27liburllib2.py”, line 521, in http_error_default

raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)

HTTPError: HTTP Error 502: Bad Gateway

Traceback (most recent call last):

File “E:WebServerWordPressto_wphi-baidu-mover_v2hi-baidu-mover_v2011-12-24.py”, line 1685, in

try:

File “E:WebServerWordPressto_wphi-baidu-mover_v2hi-baidu-mover_v2011-12-24.py”, line 1632, in main

gVal[‘statInfoDict’][‘exportedItemIdx’] += 1

File “E:WebServerWordPressto_wphi-baidu-mover_v2hi-baidu-mover_v2011-12-24.py”, line 1351, in exportEntry

calcTimeStart(“translate_post_name”)

File “E:WebServerWordPressto_wphi-baidu-mover_v2hi-baidu-mover_v2011-12-24.py”, line 849, in translateString

trans_req.add_header(‘User-Agent’, “Mozilla/4.0 (compatible;MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)”)

File “E:dev_install_rootPython27liburllib2.py”, line 126, in urlopen

return _opener.open(url, data, timeout)

File “E:dev_install_rootPython27liburllib2.py”, line 400, in open

response = meth(req, response)

File “E:dev_install_rootPython27liburllib2.py”, line 513, in http_response

‘http’, request, response, code, msg, hdrs)

File “E:dev_install_rootPython27liburllib2.py”, line 438, in error

return self._call_chain(*args)

File “E:dev_install_rootPython27liburllib2.py”, line 372, in _call_chain

result = func(*args)

File “E:dev_install_rootPython27liburllib2.py”, line 521, in http_error_default

raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)

暂时不知道是什么具体原因导致的。

虽然表面看起来是网络断了,但是好像网络是正常的,所以按理来说不应该出现这个错误才对。

后来又重新运行了一次,就没出现这个错误。

【后记 2011-12-25】

后来去看了代码,才发现,其实这里的错误,是有缘由的。

那就是,上述代码中调用了translateString函数,函数内部,调用了google的翻译功能,即向google发送请求然后获得翻译后的结果。

此翻译功能,google方面是有限制的,在一定时间内,超过一定请求,就会暂时对该ip停止此功能。

此处的错误,就是这个原因引起的,即在短时间内,发起了太多的翻译请求,所以google就会暂时停止提供此服务,导致HTTPError: HTTP Error 502: Bad Gateway的错误。

【解决办法】

解决办法很简单,那就是程序实现翻译功能的时候,保证不要一次性地,同一个短时间内,发出太多这样的翻译请求,把大量的翻译请求,分开来做,就可以了。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/422541.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

can't load apple.laf.AquaLookAndFeel (Ant in Eclipse can't find it

转载自:http://lists.apple.com/archives/java-dev/2004/Oct/msg00529.html Re: "cant load apple.laf.AquaLookAndFeel" (Ant in Eclipse cant find it) Subject: Re: "cant load apple.laf.AquaLookAndFeel" (Ant in Eclipse cant find it)Fr…

php中的会话控制器,php – codeigniter检查每个控制器中的用户会话

另一个选项是创建基本控制器。将函数放在基本控制器中,然后继承。要在CodeIgniter中实现这一点,请在应用程序的libraries文件夹中创建一个名为MY_Controller.php的文件。class MY_Controller extends Controller{public function __construct(){parent::…

EXT.NET高效开发(一)——概述

之前就有想法说说这方面,直到看到我上一篇博客《EXT.NET复杂布局(一)——工作台》的回复: 小龙3:ext.net 比使用傳統的webform控件开发时间多多少? 我就决定提前写这一系列了。小龙3应该感到荣幸。嘿嘿。 相…

php 类的注释标准,php标准注释

文件头部模板/***这是一个什么文件**此文件程序用来做什么的(详细说明,可选。)。* author richard* version $Id$* since 1.0*/函数头部注释/*** some_func* 函数的含义说明** access public* param mixed $arg1 参数一的说明* param mixed $arg2 参数二的说明* par…

前端学习(417):京东制作页面25中间部分的准备工作

引入index.css作为中部样式 <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><meta name"viewport" content"widthdevice-width, initial-scale1.0"><meta http-equiv"X-UA-Comp…

前端学习(418):京东制作页面26中间模块划分

index.css /* 中间模块 */ .grid{height: 480px;} .grid-coll1{width: 190px;height: 100%;background-color: pink;} .grid-coll2{width: 790px;height: 100%;background-color: skyblue;margin-left:10px;} .grid-coll3{width: 190px;height: 100%;background-color:purple;…

Linux下,安装配置Weblogic

Linux下&#xff0c;安装配置Weblogic2009-03-20 15:03一、安装配置JDK //如果应用不需要高版本的JDK的话&#xff0c;可以不单独安装JDK 1. 安装JDK # chmod ax jdk-1_5_0_15-linux-i586.bin # ./jdk-1_5_0_15-linux-i586.bin # mv jdk1.5.0_15 /usr/local/jdk //JDK安…

php_self nginx,nginx中的PATH_INFO为什么会影响$_SERVIER['PHP_SELF']

发现问题&#xff1a;使用ThinkPHP3.2.2在nginx部署网站&#xff0c;设置URL_MODEL2&#xff0c;使用U方法在本地生成的链接形如:/public/index但是在部署在nginx上却出现了问题 其中的URL生成了./public/index通过追寻ThinkPHP源码在ThinkPHP.php文件中发现了如下代码:if(IS_C…

前端学习(419):京东制作页面27左侧分类上

index.css /* 中间模块 */ .grid{height: 480px;} .grid-coll1{width: 190px;height: 100%;background-color: pink;} .grid-coll1 ul{padding: 20px 0;} .grid-coll1 ul li{padding-left: 12px;}.grid-coll2{width: 790px;height: 100%;background-color: skyblue;margin-lef…

java 树结构递归设计,java实现递归树形结构

数据结构递归树,数据结构递归算法,数据结构递归,数据结构递归运算,考研数据结构考递归,数据结构递归回溯,js递归树形数据结构,数据结构分治,递归变非递归用什么数据结构......通过函数递归调用来实现树形结构数据遍历的方法,其中递归函数体实现了打印指定结点的子结点功能。本方…

解析IP地址与MAC地址

一、IP地址  对于IP地址&#xff0c;相信大家都很熟悉&#xff0c;即指使用TCP/IP协议指定给主机的32位地址。IP地址由用点分隔开的4个8八位组构成&#xff0c;如192.168.0.1就是一个IP地址&#xff0c;这种写法叫点分十进制格式。IP地址由网络地址和主机地址两部分组成&…

梯度算法的matlab程序,基于MATLAB的梯度法源代码

话不多说&#xff0c;直接上干货。这是基于MATLAB的源代码&#xff0c;目标函数我选择了一个二维函数&#xff0c;根据自己需求&#xff0c;更改目标函数&#xff0c;初始迭代点以及收敛精度第一部分&#xff1a;目标函数 根据自己需求&#xff0c;更改目标函数&#xff01;&…

UNP Chapter 22 - 信号驱动I/O

22.1. 概述 信号驱动是指当某个描述字上发生了某个事件时&#xff0c;让内核通知进程。 这里描述的信号驱动不是真正的异步I/O。 第15章描述的非阻塞I/O同样不是异步I/O。在非阻塞I/O中&#xff0c;启动I/O操作后内核并不像真正的异步I/O那样立即返回&#xff0c;它只有在进程非…

break在matlab中的用法,求助这个算法运行的时候说错误: BREAK只能在FOR或WHile使用...

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼[filenamel,pathname,filterindex]uigetfile(*.*,选择图像,请选择图像)I imread(num2str(filenamel));disp(请选择添加噪声类型);disp(椒盐噪声 --1);disp(高斯噪声 --2);disp(泊松噪声 --3);disp(斑点噪声 --4);Ainput(请输入选项…

matlab双重差分模型,MATLAB中ARMA模型预测差分问题

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼这是我MATLAB预测风速的程序&#xff0c;程序不是我自己写的&#xff0c;我也是拿来参考自己的毕业作业的.每条程序旁的中文是我自己的理解&#xff0c;我也不知道对不对。程序1Xload(C:\Users\asus\Desktop\1-3.txt); 这是我的历史…

[转]AS语言基础

┏━━━━━━━━━━━━━━━━━━┓ ┃ 第一部分&#xff1a;ActionScript 3 语言基础 ┃ ┗━━━━━━━━━━━━━━━━━━┛ 第2章 ActionScript 3 语言基本元素 2.1.2 数据类型概述 简单数据类型 Boolean(布尔)、int(有符整型)、Number(浮点)、String(字符…

php strpos与strrpos,PHP开发之 strpos stripos strrpos strripos的区别

前言在日常PHP开发中strpos stripos strrpos strripos这四个函数是会经常用到的&#xff0c;但是你又掌握了多少呢&#xff1f;在这里将着中就这4个函数做一个详细的解析。正文stripos — 查找字符串首次出现的位置(不区分大小写),应使用 运算符来测试此函数的返回值&#xff…

jQuery选择元素

1、jQuery包装的CSS选择器 $(" p a.speciaClass") 2、子选择器&#xff08;个人简单的认为&#xff1a;就是在jQuery选择器里面加上了一个">"操作符&#xff0c;再具有一新的特性&#xff09; $("ul#myList>li>a").fadeOut(); 3、…

php能否缓存,PHP缓存实现

PHP缓存实现classCacheExceptionextendsException {}/*** 缓存抽象类*/abstractclassCache_Abstract {/*** 读缓存变量** param string $key 缓存下标* return mixed*/abstractpublicfunctionfetch($key);/*** 缓存变量** param string $key 缓存变量下标* param string $value…

安装SQL SERVER 2008时出现了SQL SERVER 2005 Express Tool Installed 的错误

安装SQL SERVER 2008时出现了SQL SERVER 2005 Express Tool Installed 的错误&#xff0c;这种情况一般出现在系统中已安装SQL Server 2005 的情况&#xff0c;其实不需要去卸载什么&#xff0c;只要在注册表中修改一个值即可。 HKLM\Software\Microsoft\Microsoft SQL Server\…