当我尝试在PyCharm 2.7中的OS X 10.8上运行以下Python 3.3代码(或使用Python 3.3/2.7.3启动程序运行.py文件)时:
import urllib.request
f = urllib.request.urlopen('http://www.python.org/')
print(f.read(300))
Run Code Online (Sandbox Code Playgroud)
我收到以下错误消息:
/System/Library/Frameworks/Python.framework/Versions/3.3/bin/python3 /Users/username/PycharmProjects/urllib/urllib.py
Traceback (most recent call last):
File "<frozen importlib._bootstrap>", line 1512, in _find_and_load_unlocked
AttributeError: 'module' object has no attribute '__path__'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/username/PycharmProjects/urllib/urllib.py", line 3, in <module>
import urllib.request
File "/Users/username/PycharmProjects/urllib/urllib.py", line 3, in <module>
import urllib.request
ImportError: No module named 'urllib.request'; urllib is not a package
Process finished with exit code 1 …Run Code Online (Sandbox Code Playgroud) 我正在使用httparty向某个网站发出 GET 请求。我需要响应 cookie 才能成功发出登录请求。
rest_client 让它变得非常简单,我所要做的就是:
get_request = RestClient.get('<REDACTED>')
response_cookies = get_request.cookies
# =>
{
"sessiontype"=>"mpb",
"aac"=>"741F9EC20A4C422369F7564445611591",
"Expires"=>"Sun",
"Path"=>"%2F",
"Domain"=>"<REDACTED>",
"internetbankierenmi"=>"1559079104.20480.0000",
"TSdb640d"=>"d17ca2538ee2215b647c3466d4b06da7ec33c7a21dc7217953d3ffe7d4efbe89959deba9debace3f579e71c9e27e0b6b1ea2c663"
}
Run Code Online (Sandbox Code Playgroud)
但我想对 httparty 做同样的事情。所以我的问题是如何在 httparty 中查看/访问来自 GET 请求的响应 cookie?
我创建了一个模块,在其中我使用新方法扩展了Fixnum类.但是当我require模块并尝试使用扩展方法时,它返回:
NoMethodError: undefined method `roundup' for 13:Fixnum
Run Code Online (Sandbox Code Playgroud)
这是我的模块的样子:
module EanControl
# Extend Fixnum with #roundup
class Fixnum
def self.roundup
return self if self % 10 == 0 # already a factor of 10
return self + 10 - (self % 10) # go to nearest factor 10
end
end
# More code...
end
Run Code Online (Sandbox Code Playgroud)
这就是我正在做的事情:
require 'path_to_module'
12.roundup
# => NoMethodError: undefined method `roundup' for 13:Fixnum
Run Code Online (Sandbox Code Playgroud)
我该怎么解决这个问题?
我的 Android 应用程序通过了Quixxi 漏洞扫描,其中一个高风险问题是:
Vulnerability : Using Activities/Improper Export of Android Application Activities
Severity : High
Export tag for following activities are not used properly:
com.domain.appname.activities.SplashActivity
Run Code Online (Sandbox Code Playgroud)
在清单中,它看起来像这样:
<activity
android:name=".activities.SplashActivity"
android:exported="true"
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)
当我设置android:exported="false"应用程序不再启动时,Android Studio 只显示Client not ready yet...
Quixxi 报告的漏洞如何修复?
我正在尝试填写两个表格并登录我的银行网站.
我可以获得填写用户名的第一个表单,但我似乎无法获取填写密码的表单.
这是我正在使用的代码:
from splinter import Browser
username2 = '***'
password2 = '***'
browser2 = Browser()
browser2.visit('http://mijn.ing.nl')
browser2.find_by_css('.firstfield').fill(username2)
browser2.find_by_id('#easnhbcc').fill(password2)
Run Code Online (Sandbox Code Playgroud)
这是完整的追溯:
/usr/local/bin/python2 "/Users/narekaramjan/Dropbox/Python/Python 273/Test.py"
Traceback (most recent call last):
File "/Users/narekaramjan/Dropbox/Python/Python 273/Test.py", line 26, in <module>
browser2.find_by_id('#easnhbcc').fill(password2)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/splinter/element_list.py", line 73, in __getattr__
self.__class__.__name__, name))
AttributeError: 'ElementList' object has no attribute 'fill'
Process finished with exit code 1
Run Code Online (Sandbox Code Playgroud)
我也尝试过:
browser2.find_by_name('easnhbcc').fill(password2)
Run Code Online (Sandbox Code Playgroud)
如何获取密码表格?
我正在尝试编写一个自动登录到两个网站并转到某个页面的代码.我用Splinter.
我只使用PhantomJS作为浏览器类型在"Mijn ING Zakelijk"网站上收到错误.
直到几天前,代码在20次中完美地运行了20次.但是从今天起我就收到了错误.有时代码运行正常.其他时候它没有,并给我"点击成功,但加载失败.."错误.这是完整的追溯:
## Attempting to login to Mijn ING Zakelijk, please wait.
- Starting the browser..
- Visiting the url..
- Filling the username form with the defined username..
- Filling the password form with the defined password..
- Clicking the submit button..
Traceback (most recent call last):
File "/Users/###/Dropbox/Python/Test environment 2.7.3/Splinter.py", line 98, in <module>
mijning()
File "/Users/###/Dropbox/Python/Test environment 2.7.3/Splinter.py", line 27, in mijning
attemptLogin(url2, username2, password2, defined_title2, website_name2, browser_type2)
File "/Users/###/Dropbox/Python/Test …Run Code Online (Sandbox Code Playgroud) 使用httparty我正在发出GET请求:
https://api.marktplaats.nl/api3/categories.json?oauth_token=1me6jq76h8t6rim747m7bketkd&api_ver=3.7&session=ebc565b8-659f-40f6-9d0a-96986f1d1595&screenWidth=62&screenHeight=111&app_ver=Android3.1.0
Run Code Online (Sandbox Code Playgroud)
代码A:
require 'httparty'
class Marktplaats
def categories
HTTParty.get('https://api.marktplaats.nl/api3/categories.json?oauth_token=1me6jq76h8t6rim747m7bketkd&api_ver=3.7&session=ebc565b8-659f-40f6-9d0a-96986f1d1595&screenWidth=62&screenHeight=111&app_ver=Android3.1.0')
end
end
Run Code Online (Sandbox Code Playgroud)
代码B:
require 'httparty'
class Marktplaats
@oauth_token = '1me6jq76h8t6rim747m7bketkd'
def categories
HTTParty.get("https://api.marktplaats.nl/api3/categories.json?oauth_token=#{@oauth_token}&api_ver=3.7&session=ebc565b8-659f-40f6-9d0a-96986f1d1595&screenWidth=62&screenHeight=111&app_ver=Android3.1.0")
end
end
Run Code Online (Sandbox Code Playgroud)
做的时候:
m = Marktplaats.new
m.categories
Run Code Online (Sandbox Code Playgroud)
代码A有效,但代码B没有.
调用.request.last_uri.to_s代码B的GET调用返回:
https://api.marktplaats.nl/api3/categories.json?oauth_token=&api_ver=3.7&session=ebc565b8-659f-40f6-9d0a-96986f1d1595&screenWidth=62&screenHeight=111&app_ver=Android3.1.0
Run Code Online (Sandbox Code Playgroud)
怎么可能出错?
假设我有两个充满哈希的数组,
array_a = [{'key' => 'a'}, {'key' => 'b'}, {'key' => 'c'}, {'key' => 'd'}]
array_b = [{'key' => 'a'}, {'key' => 'b'}, {'key' => 'd'}]
Run Code Online (Sandbox Code Playgroud)
我如何比较array_a和array_b返回未找到的哈希值array_b.
所以比较应该返回:
# => [{'key' => 'c'}]
Run Code Online (Sandbox Code Playgroud)