我正在尝试使用urllib for Python来打开一个URL但是我得到一个错误,其中一个特定的URL与其他URL相比看起来很正常,并且在浏览器中运行良好.
生成错误的代码是:
import cStringIO
import imghdr
import urllib2
response = urllib2.urlopen('https://news.artnet.com/wp-content/news-upload/2015/08/Brad_Pitt_Fury_2014-e1440597554269.jpg')
Run Code Online (Sandbox Code Playgroud)
但是,如果我使用类似的URL执行完全相同的操作,则不会收到错误:
import cStringIO
import imghdr
import urllib2
response = urllib2.urlopen('https://upload.wikimedia.org/wikipedia/commons/d/d4/Brad_Pitt_June_2014_(cropped).jpg')
Run Code Online (Sandbox Code Playgroud)
我在第一个例子中得到的错误是:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 154, in urlopen
return opener.open(url, data, timeout)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 431, in open
response = self._open(req, data)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 449, in _open
'_open', req)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 409, in _call_chain
result = func(*args)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1240, in https_open
context=self._context)
File …Run Code Online (Sandbox Code Playgroud) 我正在尝试将 R 脚本的错误和警告记录到外部文件中。同时我希望能够在 RStudio 的控制台中看到错误和警告(对开发和调试有用)。我正在尝试使用以下代码:
logfile <- file("my_file_path", open="wt")
sink(logfile, type="message", split = TRUE)
Run Code Online (Sandbox Code Playgroud)
但是当我尝试使用函数 sink() 拆分消息连接时,出现以下错误:
Error in sink(logfile, type = "message", split = TRUE) :
cannot split the message connection
Run Code Online (Sandbox Code Playgroud)
是否有任何解决方法或替代解决方案?
谢谢
如何检查 Firebase 实时数据库中是否存在某个值?
我正在使用以下命令,但它不起作用:
Future<bool> rootFirebaseIsExists(DatabaseReference databaseReference) async{
DataSnapshot snapshot = await databaseReference.once();
if( snapshot == null ){
print("Item doesn't exist in the db");
}else{
print("Item exists in the db");
}
return snapshot !=null;
}
print("exists?");
rootFirebaseIsExists(FirebaseDatabase.instance.reference().child("users").child('userid000').child('pushTokens').child("field_to_check"));
Run Code Online (Sandbox Code Playgroud)
问题是,即使节点不存在,快照也不为空,然后函数返回该项目存在于数据库中。
谢谢!