我正在研究Django REST 框架,我希望有单独的文件来记录数据。
我想要一个用于简单事务的文件,例如 GET、PUT、POST 等,以及一个包含错误的文件,我将在发生错误时收集这些错误。
我一直在阅读Django Logging Documentation并且我想出了一些关于如何记录信息数据的配置。配置示例如下:
设置.py
STATIC_URL = '/static/'
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static')
LOGGING_ROOT = os.path.join(STATIC_ROOT, 'logging')
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'file': {
'level': 'INFO',
'class': 'logging.FileHandler',
'filename': LOGGING_ROOT + "/info.log",
},
},
'loggers': {
'django': {
'handlers': ['file'],
'level': 'INFO',
'propagate': True,
},
},
}
Run Code Online (Sandbox Code Playgroud)
它作为文件中的预期数据样本工作:
"PUT /upload/dat.txt HTTP/1.1" 204 14
"OPTIONS / HTTP/1.1" 200 10020
"GET / HTTP/1.1" 200 9916
Run Code Online (Sandbox Code Playgroud)
我尝试在 settings.py …
我正在hashi_vault模块的帮助下从 HashiCorp 的保险库中读取 base64 文件。代码示例:
- name: Vault get b64.pfx file
set_fact:
b64_pfx: "{{ lookup('hashi_vault',
'secret={{ path_pfx }} token={{ token }} url={{ url }} cacert={{ role_path}}/files/CA.pem')}}"
Run Code Online (Sandbox Code Playgroud)
然后作为下一步,我需要将此 base64 var 解码为二进制格式并将其存储在文件中。我目前正在使用shell模块来完成这项工作。代码示例:
- name: Decode Base64 file to binary
shell: "echo {{ b64_pfx }} | base64 --decode > {{ pfxFile }}"
delegate_to: localhost
Run Code Online (Sandbox Code Playgroud)
我在网上寻找可能的解决方案,例如( 带有 base64 编码二进制文件的复制模块添加了额外的字符以及如何使用 ansible Vault 上传加密文件?)。
但是我能找到的唯一可行的解决方案是使用 shell 模块。由于这是一个老问题,是否有任何解决方法?
更新:
不要使用Python 2.7,因为b64decode过滤器上似乎存在错误(示例如下):
<localhost> ESTABLISH LOCAL CONNECTION FOR …Run Code Online (Sandbox Code Playgroud) 我是 k8s 新手,我发现了一个无法解决的问题。
我正在构建主节点的 HA 集群。我正在运行一些测试(删除一个节点并再次添加该节点)。通过这个过程我注意到etcd集群没有更新集群列表。
问题示例如下:
$ kubectl get pods -A
NAMESPACE NAME READY STATUS RESTARTS AGE
cri-o-metrics-exporter cri-o-metrics-exporter-77c9cf9746-qlp4d 0/1 Pending 0 16h
haproxy-controller haproxy-ingress-769d858699-b8r8q 0/1 Pending 0 16h
haproxy-controller ingress-default-backend-5fd4986454-kvbw8 0/1 Pending 0 16h
kube-system calico-kube-controllers-574d679d8c-tkcjj 1/1 Running 3 16h
kube-system calico-node-95t6l 1/1 Running 2 16h
kube-system calico-node-m5txs 1/1 Running 2 16h
kube-system coredns-7588b55795-gkfjq 1/1 Running 2 16h
kube-system coredns-7588b55795-lxpmj 1/1 Running 2 16h
kube-system etcd-masterNode1 1/1 Running 2 16h
kube-system etcd-masterNode2 1/1 Running 2 16h
kube-system kube-apiserver-masterNode1 …Run Code Online (Sandbox Code Playgroud) 我已经尝试了几个月来创建一个基于RFC5905的简单SNTP单客户端/服务器.最后我设法让它工作至少我认为它正常工作,但当我尝试针对真正的NTP服务器测试我的代码时(例如0.se.pool.ntp.org:123)我收到的时间戳需要重新计算.我已经尝试了几种不同的方法,但无论是现在3天,但无论我什么都没试过.
有谁知道如何将NTP时间戳转换为Unix纪元时间戳?
执行服务器的语法例如./server 127.0.0.1:5000和客户端例如./client 127.0.0.1:5000
针对真实NTP服务器执行客户端的语法,例如./client 0.se.pool.ntp.org:123
工作代码示例客户端:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <time.h>
#include <math.h>
#include <sys/timeb.h>
#include <inttypes.h>
#include <limits.h>
#include <assert.h>
#define UNIX_EPOCH 2208988800UL /* 1970 - 1900 in seconds */
typedef struct client_packet client_packet;
struct client_packet {
uint8_t client_li_vn_mode;
uint8_t client_stratum;
uint8_t client_poll;
uint8_t client_precision;
uint32_t client_root_delay;
uint32_t client_root_dispersion;
uint32_t client_reference_identifier;
uint32_t client_reference_timestamp_sec;
uint32_t client_reference_timestamp_microsec;
uint32_t client_originate_timestamp_sec;
uint32_t …Run Code Online (Sandbox Code Playgroud) 根据Android文档public void startActivityForResult(Intent intent,int requestCode,Bundle options).
我无法弄清楚如何检索我传递意图的额外包选项.
我想在调用startActivityForResult方法时传递一个带有数据的ArrayList作为额外的bundle选项.
代码示例:
ArrayList<String> list = new ArrayList<>();
list.add("test1");
list.add("test2");
Bundle bundleOptions = new Bundle();
bundleOptions.putStringArrayList("key", list);
startActivityForResult(intent, 10, bundleOptions);
Run Code Online (Sandbox Code Playgroud)
在检索数据时:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
Bundle extras = data.getExtras();
Run Code Online (Sandbox Code Playgroud)
Bundle extras不包含我想要传递的额外包.我缺少什么,我无法检索我传递给方法的额外Bundle数据?
我也试过intent.putExtra("key", bundleOptions);,也有intent.putExtra("key", list);但没有成功,并且调用方法startActivityForResult(intent, 10);但是再次没有成功.
我确信我错过了什么有人知道如何实现这一点?
感谢您的时间和精力.
我正在尝试使用模块community.kubernetes.k8s \xe2\x80\x93 使用角色中的变量(例如role/sampleRole/vars 文件)管理Kubernetes (K8s) 对象。
\n当涉及到整数点时我失败了,例如:
\n- name: sample \n community.kubernetes.k8s: \n state: present \n definition: \n apiVersion: apps/v1 \n kind: Deployment \n metadata: \n name: "{{ name }}"\n namespace: "{{ namespace }}" \n labels:\n app: "{{ app }}" \n spec:\n replicas: 2\n selector:\n matchLabels:\n app: "{{ app }}" \n template:\n metadata:\n labels:\n app: "{{ app }}" \n spec:\n containers:\n - name: "{{ name }}" \n image: "{{ image }}" \n ports:\n - containerPort: {{ containerPort …Run Code Online (Sandbox Code Playgroud) 我创建了一个 woocommerce 网页,并且尝试使用与我的页面同步的 Django/Python。从文档woocomerce post request:
data = {
"product": {
"title": "Sample of Title through POST",
"type": "simple",
"regular_price": "21.99",
"description": "Long description from Post Request",
"short_description": "Short description from Post Request",
"categories": [
9,
14
],
"images": [
{
"src": "http://example.com/wp-content/uploads/2015/01/premium-quality-front.jpg",
"position": 0
},
{
"src": "http://example.com/wp-content/uploads/2015/01/premium-quality-back.jpg",
"position": 1
}
]
}
}
print (wcapi.post("products", data).json())
Run Code Online (Sandbox Code Playgroud)
我正在使用WooCommerce REST API 的 Python 包装器,它似乎可以处理 get 请求,但我找不到让它处理 post 请求的方法。
我不断收到此错误:
TypeError: <open file 'test.jpg', mode 'rb' at …Run Code Online (Sandbox Code Playgroud) 当我们启动主主节点时,该节点会使用 ttl 为工作节点和主节点创建令牌。
根据文档kubeadm token(我也测试过并且它有效),我们可以发出命令并获取新令牌(默认为 ttl 24h):
kubeadm token create --print-join-command
Run Code Online (Sandbox Code Playgroud)
我想弄清楚是否要添加新的平面节点(辅助主节点),如何创建相关令牌?
我尝试传递一些标志,例如:
kubeadm token create --print-join-command --control-plane
Run Code Online (Sandbox Code Playgroud)
但它失败了(当然),因为这个标志不被识别。
我还通过文档发现,我们可以通过配置文件的直接链接来实现,例如 ref kubeadm-join/file 或基于 https 的发现:
kubeadm join --discovery-file path/to/file.conf # (local file)
kubeadm join --discovery-file https://url/file.conf # (remote HTTPS URL)
Run Code Online (Sandbox Code Playgroud)
就我而言,我没有本地 conf 文件或计划使用 url 链接。
有没有其他方法可以使用平面节点而不是工作节点的命令来创建新令牌?
我是一名新的程序员,现在我已经开始使用c了.我正在尝试解码IDEv3 mp3标签,我遇到了各种各样的问题.当我使用fread()和strncpy()命令时,我注意到两者都需要将\n字符作为结束参考点.(也许我错了,这只是观察)
当我打印输出时,它们产生一个不可读的字符.作为解决问题的解决方案我使用fread()4字节而不是3字节来生成(8)\n字符(整个字节),第二步我使用strncpy()和3字节分配给分配然后我用于打印的记忆.理论上,当我使用fread()时,我不应该遇到这个问题.
代码示例:
#include <stdio.h>
#include <stdlib.h>
typedef struct{
unsigned char header_id[3]; /* Unsigned character 3 Bytes (24 bits) */
}mp3_Header;
int main (int argc, char *argv[]) {
mp3_Header first;
unsigned char memory[4];
FILE *file = fopen( name.mp3 , "rb" );
if ( (size_t) fread( (void *) memory , (size_t) 4 , (size_t) 1 , (FILE *) file) !=1 ) {
printf("Could not read the file\n");
exit (0);
} /* End of if condition */
strncpy( (char *) first.header_id …Run Code Online (Sandbox Code Playgroud) 我知道这个问题似乎很熟悉C中将Char转换为Binary,但并不完全相同.我正在将一个字符数组转换为二进制整数.作为第二步,我试图在一个整数数组中连接它们.我正在将整数转换回字符,以便我可以将它们连接起来.该脚本似乎工作正常,但由于某些原因,当我打印整个字符串时,我无法理解它在字符串的开头产生一个不可打印的字符.
代码示例:
#include <stdio.h>
#include <string.h>
int main(void) {
char *temp;
char str[2];
char final[32];
for (temp = "LOCL"; *temp; ++temp) {
int bit_index;
for (bit_index = sizeof(*temp)*8-1; bit_index >= 0; --bit_index) {
int bit = *temp >> bit_index & 1;
printf("%d ", bit);
snprintf(str, 2, "%d", bit);
printf("This is test: %s\n",str);
strncat(final , str , sizeof(final) );
}
printf("\n");
}
printf("This is the array int: %s\n",final);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
有人能帮我理解我哪里错了吗?
在此先感谢您花时间和精力来帮助我.
我是 k8s 的新手,我正在尝试在主节点上部署仪表板,部署的一部分是启动指标服务器。可以在此处找到完整的文档(仪表板/指标服务器)。
我的问题与我们可以在部署后立即看到的警告有关:
$ kubectl describe pods -n kube-system metrics-server-74d7f54fdc-psz5p
Name: metrics-server-74d7f54fdc-psz5p
Namespace: kube-system
Priority: 0
Node: <none>
Labels: k8s-app=metrics-server
pod-template-hash=74d7f54fdc
Annotations: <none>
Status: Pending
IP:
IPs: <none>
Controlled By: ReplicaSet/metrics-server-74d7f54fdc
Containers:
metrics-server:
Image: my.repo.net/k8s.gcr.io/metrics-server-amd64:v0.3.6
Port: 4443/TCP
Host Port: 0/TCP
Args:
--cert-dir=/tmp
--secure-port=4443
Environment: <none>
Mounts:
/tmp from tmp-dir (rw)
/var/run/secrets/kubernetes.io/serviceaccount from metrics-server-token-d47dm (ro)
Conditions:
Type Status
PodScheduled False
Volumes:
tmp-dir:
Type: EmptyDir (a temporary directory that shares a pod's lifetime)
Medium:
SizeLimit: <unset>
metrics-server-token-d47dm: …Run Code Online (Sandbox Code Playgroud)