我正在尝试从jinja2中的python字典中检索条目,但问题是我不知道我想提前访问什么密钥 - 密钥存储在一个名为的变量中s.course.所以我的问题是我需要双重替换这个变量.我不想使用for循环,因为这将超过必要的字典方式.这是我创建的一种解决方法,但是s.course值可能会发生变化,所以显然硬编码就像这样很糟糕.我希望它的工作原理如下:
{% if s.course == "p11" %}
{{course_codes.p11}}
{% elif s.course == "m12a" %}
{{course_codes.m12a}}
{% elif s.course == "m12b" %}
{{course_codes.m12b}}
{% endif %}
Run Code Online (Sandbox Code Playgroud)
但我希望它看起来像这样:
{{course_codes.{{s.course}}}}
Run Code Online (Sandbox Code Playgroud)
谢谢!
我在AWS中设置了SQS队列.我可以使用AWS CLI和我设置的IAM凭据完美地发送和接收消息.
我想要做的是使用Camel从队列中消息,通过Spring配置.我尝试了这个例子,因为它非常明确并且重点:
https://github.com/christian-posta/camel-sqs-example
但是,我得到以下异常:
com.amazonaws.AmazonServiceException: Status Code: 403, AWS Service: AmazonSQS,
AWS Request ID: 115057f8-3c4f-5ec6-8fe9-18ea097b2730, AWS Error Code:
InvalidClientTokenId, AWS Error Message: The security token included in the
request is invalid.
Run Code Online (Sandbox Code Playgroud)
亚马逊提供了最无用的文档:
InvalidClientTokenId
我们的记录中不存在提供的X.509证书或AWS访问密钥ID.
HTTP状态代码:403
我已经仔细检查过我使用了与通过CLI使用的完全相同的IAM凭据,并且IAM用户具有允许对队列进行读/写访问的策略.我也跟周围发送额外的网址参数玩弄ACCESSKEY,秘密密钥,amazonSQSEndpoint和地区如骑骆驼记录.
为什么亚马逊说访问密钥无效或记录中不存在,我如何修复我的请求?
我有一个 Maven 项目,由一个父 POM 和几个子模块组成。它在 Intellij 中编译并运行良好(我假设它使用javac而不是 Maven)。
当我运行时maven clean install,构建由于“RequireUpperBoundDeps”而失败,这从文档中意味着构建期间解析的版本低于同一工件的依赖项版本。这是(经过清理的)输出:
[INFO] --- maven-enforcer-plugin:1.4:enforce (enforce-maven) @ my-service ---
[WARNING] Rule 1: org.apache.maven.plugins.enforcer.RequireUpperBoundDeps failed with message:
Failed while enforcing RequireUpperBoundDeps. The error(s) are [
Require upper bound dependencies error for com.h2database:h2:1.3.168 paths to dependency are:
+-com.example.services:my-service:1.0.0-SNAPSHOT
+-com.h2database:h2:1.3.168
and
+-com.example.services:my-service:1.0.0-SNAPSHOT
+-com.example.libs:my-libs:2.0.0
+-com.h2database:h2:1.3.168 (managed) <-- com.h2database:h2:1.4.190
]
Run Code Online (Sandbox Code Playgroud)
这似乎暗示这h2是 的直接依赖项my-service,但它没有在任何 poms、模块或父项中声明为这样。h2应该只来自my-libs. 此外,它声称h2“管理”为 version 1.3.168。我不知道它从哪里得到这些信息。my-libs使用h2 …
我正在创建一个非常简单的 Swing GUI,其中包含一个可滚动文本区域。但是,我在用户界面的响应能力方面遇到了一些问题。这是我用来尝试一些不同配置的类:
public class ComponentSample {
public void createWindow() {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
TextArea textArea = new TextArea(getFillerText(), 40, 120);
setViews(frame, textArea);
frame.pack();
frame.setVisible(true);
}
private void setViews(JFrame frame, TextArea textArea) {
...
}
private String getFillerText() {
String threeLines = "Why isn't scrolling smooth? \nSteve Jobs would not approve\n\n";
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < 100; i++) {
stringBuilder.append(threeLines);
}
return stringBuilder.toString();
}
public static void main(String[] args) throws …Run Code Online (Sandbox Code Playgroud) 我有一个python3脚本script.py,在其中我要实例化一个在clazz.py中定义的Foobar类。但是,当我尝试导入时,我得到:
$ python3 script.py
...
SystemError: Parent module '' not loaded, cannot perform relative import
Run Code Online (Sandbox Code Playgroud)
这是我的文件结构:
python_import/
??? __init__.py
??? clazz.py
??? script.py
Run Code Online (Sandbox Code Playgroud)
clazz.py:
class Foobar():
def __init__(self):
print("initialized a foobar")
Run Code Online (Sandbox Code Playgroud)
script.py:
from .clazz import Foobar
foobar = Foobar()
Run Code Online (Sandbox Code Playgroud)
它运行很好,如果我摆脱.的import; 但是,如果执行此操作,则我的IDE(Intellij IDEA)会以红色下划线标记导入内容,并且不会自动完成任何操作。我相信.在python3中包含正确,并且Intellij似乎很喜欢,所以除非删除它,否则为什么我的程序无法运行?
我已阅读http://www.diveintopython3.net/porting-code-to-python-3-with-2to3.html#import,http://python.readthedocs.org/en/latest/reference/import.html,如何在同一目录或子目录中导入类?,Python 3中的相对导入和Python 3中的相对导入不起作用。
我怀疑它可能与virtualenv有关,但是a)我不明白为什么工作目录不会成为PYTHONPATH的一部分,并且b)我不太确定如何在virtualenv中进行更改-Intellij设置了它为我。
Groovy似乎弄乱了我的存根。以下测试通过:
MockitoStubTest2.java:
public class MockitoStubTest2 {
@Test
public void testStubbing() {
MyInterface myInterface = mock(MyInterface.class);
when(myInterface.someMethod(isA(MyClass.class))).thenReturn("foobar");
assertEquals("foobar", myInterface.someMethod(new MyClass()));
}
private interface MyInterface {
String someMethod(MyClass arg);
String someMethod(String arg);
}
private static class MyClass {}
}
Run Code Online (Sandbox Code Playgroud)
但是,此失败并显示groovy.lang.GroovyRuntimeException: Ambiguous method overloading for method ...#someMethod:
MockitoStubTest3.groovy:
public class MockitoStubTest3 {
@Test
public void testStubbing() {
MyInterface myInterface = mock(MyInterface.class);
when(myInterface.someMethod(isA(MyClass.class))).thenReturn("foobar");
assertEquals("foobar", myInterface.someMethod(new MyClass()));
}
private interface MyInterface {
String someMethod(MyClass arg);
String someMethod(String arg);
}
private static class MyClass …Run Code Online (Sandbox Code Playgroud) 我有一个基本上是服务代理的应用程序.该应用程序本身建在泽西岛上,由Jetty提供服务.我有这个资源方法:
@POST
@Path("/{default: .*}")
@Timed
@Consumes("application/x-www-form-urlencoded")
public MyView post(@Context UriInfo uriInfo, @Context HttpServletRequest request) {
...
}
Run Code Online (Sandbox Code Playgroud)
用户提交POST表单.所有POST请求都通过此方法.除了一个细节之外,UriInfo和HttpServletRequest被适当地注入:似乎没有参数.这是我从终端发送的请求:
POST /some/endpoint HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Content-Length: 15
Content-Type: application/x-www-form-urlencoded; charset=utf-8
Host: localhost:8010
User-Agent: HTTPie/0.9.2
foo=bar&biz=baz
Run Code Online (Sandbox Code Playgroud)
POST主体显然包含2个参数:foo和biz.但是当我尝试在我的代码(request.getParameterMap)中获取它们时,结果是一个大小为0的地图.
如何从资源方法中访问这些参数或此参数字符串?如果重要,那么使用的实现HttpServletRequest是org.eclipse.jetty.server.Request.
java ×4
python ×2
amazon-sqs ×1
apache-camel ×1
dictionary ×1
groovy ×1
h2 ×1
http ×1
import ×1
jersey ×1
jetty ×1
jinja2 ×1
macos ×1
maven ×1
mockito ×1
python-3.x ×1
spring ×1
substitution ×1
swing ×1
variables ×1