我正在使用Python请求包发送http请求.我想在请求会话对象中添加一个代理.例如.
session = requests.Session()
session.proxies = {...} # Here I want to add a single proxy
Run Code Online (Sandbox Code Playgroud)
目前,我正在遍历一堆代理,并且在每次迭代时都会创建一个新会话.我只想为每次迭代设置一个代理.
我在文档中看到的唯一例子是:
proxies = {
"http": "http://10.10.1.10:3128",
"https": "http://10.10.1.10:1080",
}
requests.get("http://example.org", proxies=proxies)
Run Code Online (Sandbox Code Playgroud)
我试图遵循这一点,但无济于事.这是我的脚本代码:
# eg. line = 59.43.102.33:80
r = s.get('http://icanhazip.com', proxies={'http': 'http://' + line})
Run Code Online (Sandbox Code Playgroud)
但是我收到一个错误:
requests.packages.urllib3.exceptions.LocationParseError: Failed to parse 59.43.102.33:80
Run Code Online (Sandbox Code Playgroud)
如何在会话对象上设置单个代理?
我正在尝试安装PyQueryvia pip但是我收到了一个我不明白的错误.我使用的命令是:
sudo pip install pyquery
Run Code Online (Sandbox Code Playgroud)
我得到以下输出:
Requirement already satisfied (use --upgrade to upgrade): pyquery in /usr/local/lib/python2.7/dist-packages
Downloading/unpacking lxml>=2.1 (from pyquery)
Running setup.py egg_info for package lxml
/usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'bugtrack_url'
warnings.warn(msg)
Building lxml version 3.3.0.
Building without Cython.
ERROR: /bin/sh: 1: xslt-config: not found
** make sure the development packages of libxml2 and libxslt are installed **
Using build configuration of libxslt
Downloading/unpacking cssselect (from pyquery)
Running setup.py egg_info for package cssselect
no previously-included …Run Code Online (Sandbox Code Playgroud) 我正在尝试在OSX上安装Phalcon Dev Tools.我安装了Phalcon并且工作正常.
我按照这里的说明操作:http://docs.phalconphp.com/en/latest/reference/mactools.html
当我phalcon在终端中运行命令时,我得到以下输出:
Phalcon Developer Tools Installer
Make sure phalcon.sh is in the same dir as phalcon.php and that you are running this with sudo or as root.
Installing Devtools...
Working dir is: /Users/me/phalcon-tools
Done. Devtools installed!
Run Code Online (Sandbox Code Playgroud)
现在我该如何使用devtools?当我输入phalcon commands输出与上面完全相同,并继续告诉我它已安装.
我在这里错过了什么吗?
我在phalcon.sh脚本中注意到,最后它有:
if check_install; then
php "$PTOOLSPATH/phalcon.php" $*
fi
Run Code Online (Sandbox Code Playgroud)
因此,如果check_install通过,请运行phalcon.php.我试图手动运行这个脚本,终端没有任何反应.
$PTOOLSPATH被定义为.我确认使用了这个echo $PTOOLSPATH.
我/usr/bin/env php是对的,并指向MAMP的PHP.我现在使用MAMP安装了Phalcon.我的PHP是正确的:
which php
/Applications/MAMP/bin/php/php5.5.23/bin/php
Run Code Online (Sandbox Code Playgroud)
检查phalcon.php脚本,并使用xdebug,我发现问题在于:
if (!extension_loaded('phalcon')) { …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用wp_enqueue_styleWordpres Codex上的建议加载脚本,但脚本似乎没有包含在源代码中.这是正确的方法吗?
function load_scripts() {
wp_enqueue_style('bootstrap.css', get_template_directory_uri() . '/css/bootstrap.min.css');
}
add_action('wp_enqueue_scripts', 'load_scripts');
Run Code Online (Sandbox Code Playgroud) 我对主机字节顺序和网络字节顺序非常困惑.我知道网络字节顺序是大端.我知道在我的情况下主机字节顺序是小端.
那么,如果我打印数据,我需要转换为主机字节顺序才能获得正确的值?
我的问题是我正在尝试打印返回的数据值htonl.这是我的例子:
#include <stdio.h>
#include <netinet/in.h>
int main(int argc, char *argv[])
{
int bits = 12;
char *ip = "132.89.39.0";
struct in_addr addr;
uint32_t network, netmask, last_addr;
uint32_t total_hosts;
inet_aton(ip, &addr);
printf("Starting IP:\t%s\n", inet_ntoa(addr.s_addr));
netmask = (0xFFFFFFFFUL << (32 - bits)) & 0xFFFFFFFFUL;
netmask = htonl(netmask);
printf("Netmask:\t%s\n", inet_ntoa(netmask));
network = addr.s_addr & netmask;
printf("Network:\t%s\n", inet_ntoa(network));
printf("Total Hosts:\t%d\n", ntohl(netmask));
return 0;
Run Code Online (Sandbox Code Playgroud)
}
printf("Total Hosts:\t%d\n", ntohl(netmask));打印正确的值,但它用减号打印.如果我使用%u我得到错误的值.
我哪里错了?
%d输出为:
Starting IP: 132.89.39.0
Netmask: …Run Code Online (Sandbox Code Playgroud)