我正在构建一个Docker容器,它从bitbucket中提取perl/mojolicious repo,但我遇到了问题.我有这样的Dockerfile:
# DOCKER-VERSION 0.3.4
FROM perl:latest
MAINTAINER My Name myname@name.com
# Update aptitude with new repo
RUN apt-get update
# Install software
RUN apt-get install -y git
# Make ssh dir
RUN mkdir /root/.ssh/
# Copy over private key, and set permissions
ADD repo-key /root/.ssh/id_rsa
# Create known_hosts
RUN touch /root/.ssh/known_hosts
# Add bitbuckets key
RUN ssh-keyscan bitbucket.org >> /root/.ssh/known_hosts
RUN curl -L http://cpanmin.us | perl - App::cpanminus
RUN cpanm Mojolicious
RUN cachebuster=b953b35 git clone -b branch git@bitbucket.org:org/project.git
EXPOSE …Run Code Online (Sandbox Code Playgroud) git perl amazon-web-services docker amazon-elastic-beanstalk
我使用try/except块作为替代if/elif,有一堆ands.我正在寻找一个列表,并替换一些元素,如果它有x和x和x等.在我的项目中,我必须检查6个东西,这些吸引我使用try/exceptwith .index()将导致错误,如果元素isn不存在.
类比看起来像这样:
colors = ['red', 'blue', 'yellow', 'orange']
try:
red_index = colors.index('red')
blue_index = colors.index('blue')
colors[red_index] = 'pink'
colors[blue_index] = 'light blue'
except ValueError:
pass
try:
yellow_index = colors.index('yellow')
purple_index = colors.index('purple')
colors[yellow_index] = 'amarillo'
colors[purple_index] = 'lavender'
except ValueError:
pass
Run Code Online (Sandbox Code Playgroud)
因此,如果colors数组不包含'purple'还有'yellow',我不希望阵列,以改变.
我对这种方法有点警惕,因为它似乎是滥用try/except.但是它比替代方案要短得多,因为index无论如何我都必须抓住元素,所以我想知道这是否存在明显的问题,或者这是否足够疯狂以至于其他开发人员会讨厌它.
我正在尝试从 The Trade Desk 的(沙盒)api 获取身份验证令牌,但我收到了 400 响应,指出:
“将 Content-Type 'application/json' 读取为 JSON 时出错:解析值时遇到意外字符:L。路径 '',第 0 行,位置 0。”
整体response.json():
{u'ErrorDetails': [{u'Reasons': [u"Error reading Content-Type 'application/json' as JSON: Unexpected character encountered while parsing value: L. Path '', line 0, position 0."], u'Property': u'TokenRequest'}], u'Message': u'The request failed validation. Please check your request and try again.'}
Run Code Online (Sandbox Code Playgroud)
我的脚本(可运行):
import requests
def get_token():
print "Getting token"
url = "https://apisb.thetradedesk.com/v3/authentication"
headers = {'content-type': 'application/json'}
data = {
"Login":"logintest",
"Password":"password",
"TokenExpirationInMinutes":60
}
response = …Run Code Online (Sandbox Code Playgroud)