当我只是运行以下代码时,我总是得到这个错误.
s3 = boto3.resource('s3')
bucket_name = "python-sdk-sample-%s" % uuid.uuid4()
print("Creating new bucket with name:", bucket_name)
s3.create_bucket(Bucket=bucket_name)
Run Code Online (Sandbox Code Playgroud)
我保存了我的凭据文件
C:\Users\myname\.aws\credentials,Boto应该从那里读取我的凭据.
我的设置错了吗?
这是输出boto3.set_stream_logger('botocore', level='DEBUG').
2015-10-24 14:22:28,761 botocore.credentials [DEBUG] Skipping environment variable credential check because profile name was explicitly set.
2015-10-24 14:22:28,761 botocore.credentials [DEBUG] Looking for credentials via: env
2015-10-24 14:22:28,773 botocore.credentials [DEBUG] Looking for credentials via: shared-credentials-file
2015-10-24 14:22:28,774 botocore.credentials [DEBUG] Looking for credentials via: config-file
2015-10-24 14:22:28,774 botocore.credentials [DEBUG] Looking for credentials via: ec2-credentials-file
2015-10-24 14:22:28,774 botocore.credentials [DEBUG] Looking …Run Code Online (Sandbox Code Playgroud) 我使用以下IntelliJ.
IntelliJ IDEA 2017.2 EAP
Build #IU-172.2953.9, built on June 14, 2017
IntelliJ IDEA EAP User
Expiration date: July 14, 2017
JRE: 1.8.0_152-release-915-b3 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Mac OS X 10.12.5
Run Code Online (Sandbox Code Playgroud)
我在构建项目时遇到了java.lang.StackOverflowError.
有没有人陷入同样的境地?
建立消息↓
Information:java: The system is out of resources.
Information:java: Consult the following stack trace for details.
Information:java: at com.sun.tools.javac.code.Types$13.visitClassType(Types.java:1955)
Information:java: at com.sun.tools.javac.code.Type$ClassType.accept(Type.java:786)
Information:java: at com.sun.tools.javac.code.Types$DefaultTypeVisitor.visit(Types.java:4571)
Information:java: at com.sun.tools.javac.code.Types.asSuper(Types.java:1952)
Information:java: at com.sun.tools.javac.code.Types.unboxedType(Types.java:3987)
Information:java: at com.sun.tools.javac.code.Types.unboxedTypeOrType(Types.java:3998)
Information:java: at com.sun.tools.javac.comp.DeferredAttr$ArgumentExpressionKind.standaloneKind(DeferredAttr.java:1135)
Information:java: at com.sun.tools.javac.comp.DeferredAttr$DeferredChecker.visitLiteral(DeferredAttr.java:1296) …Run Code Online (Sandbox Code Playgroud) 我最近设置了一个实例(m4.4xlarge).
当我执行' lscpu'命令时,输出看起来如下所示:
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 16
On-line CPU(s) list: 0-15
Thread(s) per core: 2
Core(s) per socket: 8
CPU socket(s): 1
.
.
.
Run Code Online (Sandbox Code Playgroud)
这是否意味着只能使用8个核心?
如果是这样,其余的CPU是什么?
我在循环语句中有以下代码.
在循环中,字符串被附加到sb(StringBuilder)并检查sb的大小是否已达到5MB.
if (sb.toString().getBytes("UTF-8").length >= 5242880) {
// Do something
}
Run Code Online (Sandbox Code Playgroud)
这工作正常,但它很慢(在检查大小方面)
最快的方法是什么?
假设我有两个表,其中列分别为 VARCHAR2、CLOB和 NUMBER 类型 Col1、Col2 和 Col3。
\n\n我怎样才能得到这些表的差异?(即存在于表 B中但不存在于表 A中的记录列表)
\n\nTable A:\n\xe2\x95\x94\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\xa6\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\xa6\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x97\n\xe2\x95\x91 Col1 \xe2\x95\x91 Col2 \xe2\x95\x91 Col3 \xe2\x95\x91\n\xe2\x95\xa0\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\xac\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\xac\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\xa3\n\xe2\x95\x91 P1111 \xe2\x95\x91 some_long_text1 \xe2\x95\x91 1234 \xe2\x95\x91\n\xe2\x95\x91 P1111 \xe2\x95\x91 some_long_text1 \xe2\x95\x91 1233 \xe2\x95\x91\n\xe2\x95\x91 P1111 \xe2\x95\x91 some_long_text2 \xe2\x95\x91 1233 \xe2\x95\x91\n\xe2\x95\x9a\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\xa9\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\xa9\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x9d\n\nTable B:\n\xe2\x95\x94\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\xa6\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\xa6\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x97\n\xe2\x95\x91 Col1 \xe2\x95\x91 Col2 \xe2\x95\x91 Col3 \xe2\x95\x91\n\xe2\x95\xa0\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\xac\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\xac\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\xa3\n\xe2\x95\x91 P1111 \xe2\x95\x91 some_long_text1 \xe2\x95\x91 1234 \xe2\x95\x91\n\xe2\x95\x91 P1111 \xe2\x95\x91 some_long_text1 \xe2\x95\x91 1235 \xe2\x95\x91\n\xe2\x95\x91 P1112 \xe2\x95\x91 some_long_text2 \xe2\x95\x91 1233 \xe2\x95\x91\n\xe2\x95\x9a\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\xa9\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\xa9\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x9d\n\nExpected results:\n\xe2\x95\x94\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\xa6\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\xa6\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x97\n\xe2\x95\x91 Col1 \xe2\x95\x91 Col2 \xe2\x95\x91 Col3 \xe2\x95\x91\n\xe2\x95\xa0\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\xac\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\xac\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\xa3\n\xe2\x95\x91 P1111 \xe2\x95\x91 some_long_text1 \xe2\x95\x91 …Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个轮询方法,定期轮询服务器以检查是否已创建zip文件.
我想要完成的是以下内容:
这是我的代码片段↓
var success: boolean = false;
//1. requests a server to create a zip file
this.apiRequest.downloadRequest(params,ApiUrl.URL_FOR_DOWNLOAD_REQUEST)
.then((resObj) => {
var apiRes: IDownloadService = resObj.data;
if (apiRes.status[0].statusCode == "000") {
success = true;
} else {
//Error
}
}).then(() => {
if (success) {
//2. polls the server to check if the zip file is ready
<- Polling method? ->
this.polling(params).then((zipUrl) => {
console.log(zipUrl); //always logs zipUrl
//some subsequent process...
});
}
});
Run Code Online (Sandbox Code Playgroud)
任何人都可以提供一些在这种情况下可行的轮询方法示例吗?
添加:
private …Run Code Online (Sandbox Code Playgroud) 我正在尝试为依赖于另一个私有方法的方法编写一些单元测试。- 如下例所示:
def is_member_of(self, group_name):
members = self.__get_group_members(group_name)
Run Code Online (Sandbox Code Playgroud)
我想模拟的私有方法是__get_group_members;我还想模拟私有属性,__user_id因为它将在is_member_of函数中使用(上面的示例中未显示)。
到目前为止我所拥有的:
import unittest
from unittest import mock
class Test(unittest.TestCase):
group_data = []
user_id = 'test_user_id'
def mock_dependencies(self, x):
x.__user_id = mock.PropertyMock(return_value=self.user_id)
x.__get_group_members = mock.MagicMock(return_value=self.group_data)
def first_test(self):
x = A(('name', 'group'))
self.mock_dependencies(x)
x.is_member_of('test_group')
Run Code Online (Sandbox Code Playgroud)
当我调用x.is_member_of()模拟时,它没有按预期工作。
假设我下面有一个案例类
case class SomeCaseClass[M] private (
value: String
)
Run Code Online (Sandbox Code Playgroud)
在另一个文件中,我具有以下特征和对象。
trait SomeTrait[A] {
def get(oldId: String): A
:
}
object SomeObject {
private[this] def init[A](): SomeTrait[A] = new SomeTrait[A] {
def get(oldId: String): A = id(oldId)
:
}
val aaa: SomeTrait[String] = init[String]()
val bbb: SomeTrait[SomeCaseClass[String]] = init[SomeCaseClass[String]]()
}
Run Code Online (Sandbox Code Playgroud)
我应该如何修改代码,以便将init方法限制为只能与SomeCaseClass [_]类型一起使用,而不能与上述任何类型的字符串一起使用?
理想情况下,对代码进行一些修改,该行val aaa: SomeTrait[String] = init[String]()应导致编译错误。
我有一个简单的类,如下所示.
我想要用这个类实现的是将实例序列化为一个字节数组,但我一直在努力java.io.NotSerializableException.
我的代码出了什么问题?
难道这只是一个指针实例时调用构造函数,而不是实际的实例对象创建?
class XXX {
private String someStr;
public XXX(String someStr){
this.someStr = someStr;
}
public byte[] toByteArray(){
byte[] output = null;
try(ByteArrayOutputStream out = new ByteArrayOutputStream();
ObjectOutputStream stream = new ObjectOutputStream(out)) {
stream.writeObject(this);
output = out.toByteArray();
}catch(Exception e){
}
return output;
}
}
XXX aX = new XXX("some string");
aX.toByteArray();
Run Code Online (Sandbox Code Playgroud) 假设我有两个异步函数,A和B,它们彼此独立.
我想要做的是按顺序多次执行这些功能,如下所示
A -> B -> A -> B -> A -> ...
Run Code Online (Sandbox Code Playgroud)
B等到A结束,反之亦然.
以下是我到目前为止所做的工作,我知道它不会按照我想要的方式工作.
function A() {
var promise = new Promise...
...
return promise;
}
function B() {
var promise = new Promise...
...
return promise;
}
for(var i=0; i<200; i++) {
var p1 = A();
p1.then(() => {
var p2 = B();
// ----
}
}
Run Code Online (Sandbox Code Playgroud)
我该如何更改代码?
假设我有两个用户,A 和 B。
A 可以访问所有可用的资源,但 B 只能访问它们的一部分。
防止 B 访问 B 没有权限的资源的正确方法是什么?
我应该创建某种白名单来指定只有 URL B 可以访问吗?
以下代码段是我目前拥有的。它是一个中间件,用于检查是否允许每个请求访问特定的 URL。
const ALLOWED_URLS = ['api/resource1', 'api/resource2', 'api/resource3'];
const sessionCheck = (req, res, next) => {
const url = req.originalUrl;
// check whether accessing URL is allowed
}
Run Code Online (Sandbox Code Playgroud)
还有比这更好的方法吗?
我有一些如下所示的通用方法。
通过以这种方式定义方法,Scala 无法推断出类型 A 和 B 出于某种原因。
def someMethod[A <: UpperBoundA, B <: UpperBoundB](m: Map[A, B], condition: A => Boolean): Option[B] =
m.filterKeys(condition).headOption.map(_._2)
Run Code Online (Sandbox Code Playgroud)
但是当通过应用柯里化转换如下方法时,Scala 设法正确推断类型。
def someMethod[A <: UpperBoundA, B <: UpperBoundB](m: Map[A, B])(condition: A => Boolean): Option[B] =
m.filterKeys(condition).headOption.map(_._2)
Run Code Online (Sandbox Code Playgroud)
以下是所有方法的调用方式
someMethod(m, _.someField == "aaa") // not working for some reason
someMethod[Key, Value](m, _.id == "aaa") // working
someMethod(m)(_.someField == "aaa") // working(with currying)
Run Code Online (Sandbox Code Playgroud)
这是为什么?
java ×3
boto ×2
boto3 ×2
javascript ×2
python ×2
python-3.x ×2
scala ×2
ajax ×1
amazon-ec2 ×1
angularjs ×1
asynchronous ×1
cpu ×1
cpu-cores ×1
cpu-usage ×1
express ×1
java-8 ×1
node.js ×1
oracle ×1
oracle12c ×1
plsql ×1
typescript ×1
utf-8 ×1