我发现很难弄清楚当令牌因某种原因在数据库中被删除时如何返回 401。
让我解释。
我的常规设置使用 SessionAuthentication 和 TokenAuthentication 方案。
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.TokenAuthentication',
),
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticated',
),
'DEFAULT_FILTER_BACKENDS': (
'rest_framework.filters.DjangoFilterBackend',
),
'DATETIME_FORMAT': '%a, %d %b %Y %H:%M:%S %z',
'DATETIME_INPUT_FORMATS': ['iso-8601', '%Y-%m-%d %H:%M:%S', '%a, %d %b %Y %H:%M:%S %z'],
'DATE_FORMAT': '%Y-%m-%d',
'DATE_INPUT_FORMATS': ['%Y-%m-%d', '%m/%d/%YYYY'],
'PAGE_SIZE': 20
}
Run Code Online (Sandbox Code Playgroud)
我有一个生成身份验证令牌的视图,如下所示:
class AcmeObtainAuthToken(APIView):
throttle_classes = ()
permission_classes = ()
parser_classes = (parsers.FormParser, parsers.MultiPartParser, parsers.JSONParser,)
renderer_classes = (renderers.JSONRenderer,)
serializer_class = AcmeAuthTokenSerializer
def post(self, request, *args, **kwargs):
serializer = self.serializer_class(data=request.data)
serializer.context = {'request': …Run Code Online (Sandbox Code Playgroud) 我有一个dll项目,当在Release配置中构建项目时,我收到以下警告:
MSVCRT.lib(cinitexe.obj):警告LNK4098:defaultlib'msvcrtd.lib'与使用其他库冲突; 使用/ NODEFAULTLIB:库
这只是一个警告,但我不知道是否应该考虑到这一点.
对于我发现的,它们都是多线程库,正常版本和调试版本.我的DLL使用多线程,我可以调试它,虽然我使用boost:thread,所以我真的不知道如果我需要这个Windows特定的库进行调试或发布构建...
亲切的问候,Alex
好吧,我按照BuschnicK的建议并使用/ VERBOSE:LIB链接器标志我发现我在Debug配置中链接到这些库:
boost_filesystem-vc100-mt-gd-1_44.lib:libboost_system-vc100-mt-gd-1_44.lib:libboost_thread-vc100-mt-gd-1_44.lib:libboost_date_time-vc100-mt-gd-1_44.lib:
我在Release配置中也一样,主要是因为我没有明确指定"明确".因此,我在Release中将它们改为:
boost_filesystem-vc100-mt-1_44.lib:libboost_system-vc100-mt-1_44.lib:libboost_thread-vc100-mt-1_44.lib:libboost_date_time-vc100-mt-1_44.lib:
这似乎工作但我仍然得到第一个警告,直到我意识到我在我的发布配置中也有_DEBUG预处理器定义,删除它,它现在正在工作.
谢谢大家的帮助!!
发送到Google Cloud Vision的base64编码图像出现问题。有趣的是,如果我通过URI发送图像,则可以正常工作,因此我怀疑编码方式有误。
这是交易:
from google.cloud import vision
import base64
client = vision.ImageAnnotatorClient()
image_path ='8720911950_91828a2aeb_b.jpg'
with open(image_path, 'rb') as image:
image_content = image.read()
content = base64.b64encode(image_content)
response = client.annotate_image({'image': {'content': content}, 'features': [{'type': vision.enums.Feature.Type.LABEL_DETECTION}],})
print(response)
Run Code Online (Sandbox Code Playgroud)
我总是得到的答复是:
error {
code: 3
message: "Bad image data."
}
Run Code Online (Sandbox Code Playgroud)
如果我尝试使用URI代替:
response = client.annotate_image({'image': {'source': {'image_uri': 'https://farm8.staticflickr.com/7408/8720911950_91828a2aeb_b.jpg'}}, 'features': [{'type': vision.enums.Feature.Type.LABEL_DETECTION}],})
Run Code Online (Sandbox Code Playgroud)
响应还可以...
label_annotations {
mid: "/m/0168g6"
description: "factory"
score: 0.7942917943000793
}
label_annotations {
mid: "/m/03rnh"
description: "industry"
score: 0.7761002779006958
}
Run Code Online (Sandbox Code Playgroud)
知道这里有什么问题吗?
这是一个绝对的noob问题,但我似乎没有在任何地方找到适当的答案,所以在这里,给出这个代码:
#include <stdio.h>
#include <stdlib.h>
void initialize( char * buffer)
{
buffer = malloc(1);
*buffer='a';
}
int main(void) {
char * buff;
buff = malloc(sizeof(char));
*buff = 'b';
initialize(buff);
puts("Contents of buffer are: ");
puts(buff);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
main的输出总是'b',这对我来说真的很奇怪.我认为通过传递指针初始化我可以修改在main中声明的指针的值,但由于某种原因它似乎是通过值传递变量,并且在返回时我有在main中指定的值,因此'b' .
我想知道为什么这个...我应该传递对指针的引用吗?像char*&??
问候,亚历克斯
我正在开发一个OSGi Equinox软件包,我想添加一些日志记录,主要是重定向到OSGi控制台,仅用于调试目的.
在放弃使用log4j之后,由于Equinox(LogService和ExtendedLogService)中有几个日志服务,我发现这篇文章描述了如何使用LogService:
所以我提出了一个看起来像这样的Activator:
package org.example.servlet;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.service.log.LogService;
import org.osgi.util.tracker.ServiceTracker;
import org.eclipse.equinox.log.ExtendedLogService;
public class Activator implements BundleActivator {
private static BundleContext context;
private ServiceTracker logServiceTracker;
private LogService logService;
static BundleContext getContext() {
return context;
}
/*
* (non-Javadoc)
* @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
*/
public void start(BundleContext bundleContext) throws Exception {
Activator.context = bundleContext;
// create a tracker and track the log service
logServiceTracker = new ServiceTracker(context, LogService.class.getName(), null);
logServiceTracker.open();
// grab the service
logService …Run Code Online (Sandbox Code Playgroud) 我正在运行一个 Flask 应用程序,它基本上是从 Twitter 中提取推文。虽然使用嵌入式 Flask 服务器运行应用程序没有任何问题,但在 gUnicorn 中运行时,我收到重复的推文,主要是因为我有 2 个线程接收来自 Twitter 的回调。
例如,如果我使用
蟒蛇应用程序.py
当收到推文时,我得到了这个预期的输出,看到我在记录器输出中附加了线程信息(第一个参数):
140721974449920 2015-03-12 17:59:13,030 INFO: Got message from streaming Twitter API! [in /home/mosquito/git/opencoast_streamer/app.py:83]
140721974449920 2015-03-12 17:59:14,646 INFO: Got message from streaming Twitter API! [in /home/mosquito/git/opencoast_streamer/app.py:83]
140721974449920 2015-03-12 17:59:49,031 INFO: Got message from streaming Twitter API! [in /home/mosquito/git/opencoast_streamer/app.py:83]
Run Code Online (Sandbox Code Playgroud)
如您所见,时间戳看起来也有效,检查我存储它的 mongo 集合,我看到文档没问题。然后,如果我使用 gunicorn 启动应用程序:
gunicorn app:app -b localhost:8000 --debug
Run Code Online (Sandbox Code Playgroud)
然后检查日志,我可以看到 2 个不同的线程正在获取数据:
139883969844992 2015-03-12 17:52:05,104 INFO: Got message from streaming Twitter API! [in /home/mosquito/git/opencoast_streamer/app.py:83]
139883961452288 2015-03-12 17:52:05,106 …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 asyncio 读取多个文件(CSV),但我不想在执行此操作时阻止主事件循环。
所以我检查了 AIOfile,它似乎承诺读取不会阻塞。虽然这可能是真的,但以下代码片段需要花费大量时间才能完成,但它与此处的示例基本相同https://github.com/mosquito/aiofile#read-file-line-by-line
import asyncio
from aiofile import AIOFile, LineReader
from pathlib import Path
import time
counter = 0
async def main():
path = 'test_data'
global counter
data_dir = Path(path)
files_in_basepath = (entry for entry in data_dir.iterdir() if entry.is_file())
list_of_files = [(path + '/' + file.name, file) for file in files_in_basepath]
for file in list_of_files:
line_count = 0
async with AIOFile(file[0]) as afp:
await afp.fsync()
async for line in LineReader(afp):
#print(line)
values = ''
line_values = line.split(',') …Run Code Online (Sandbox Code Playgroud) 我有一个PostgreSQL表,其中包含"没有时区的时间戳"字段.在某个给定点我查询此表,我需要那些记录,其中时间戳在执行查询的同一天内.这是代码:
DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy/MM/dd HH:00:00");
DateTime dt = new DateTime();
String timeStampAsString = dt.toString(formatter);
String select = "SELECT * FROM " + tableName + " WHERE " + tableName + ".timestamp >= '"+ timeStampAsString + "'";
pst = dbConnection.prepareStatement(select);
pst.execute();
Run Code Online (Sandbox Code Playgroud)
我使用的乔达在这里你可以看到,我也填充该表中其他一些问题,所以我现在的格式是正确的(YYYY/MM/DD HH:00:00).不确定我是否可以直接将查询传递给查询而不是转换为String,但这并不会让我感到困扰.
由于查询条件是> ="NOW"时间戳,因此它不太可能返回某些内容.我需要的是在"NOW"时间戳的同一天内获取记录.我想我必须要求上限和下限,但我不确定如何计算此查询的下边界...任何想法?
谢谢!
有人知道如何禁用日志记录或减少 Hive JDBC 驱动程序的详细程度吗?
我正在使用 hive-jdbc-0.8.1.jar 并且我也在远程调试,因此,当查询一个巨大的数据集时,控制台消息的日志记录需要永远。
我试图将我的 log4java 属性设置为仅 ERROR 级别:
Properties log4jProperties = new Properties();
log4jProperties.setProperty("log4j.rootLogger", "DEBUG, myConsoleAppender");
log4jProperties.setProperty("log4j.appender.myConsoleAppender", "org.apache.log4j.ConsoleAppender");
log4jProperties.setProperty("log4j.appender.myConsoleAppender.layout", "org.apache.log4j.PatternLayout");
log4jProperties.setProperty("log4j.appender.myConsoleAppender.layout.ConversionPattern", "%-5p %c %x - %m%n");
PropertyConfigurator.configure(log4jProperties);
log.setLevel(Level.ERROR);
Run Code Online (Sandbox Code Playgroud)
但是 hive jdbc 似乎忽略了这些设置。
此链接上的这个人建议进行一些修改,但他使用 Jython,所以我不知道如何复制他正在做的事情......有任何线索吗?
谢谢。!
我正处于这样一种情况,我希望将内联样式应用于基于我在控制器中定义的标志的DOM元素.这背后的原因是我无法更改视图中使用的现有CSS,也无法扩展它.
也就是说,这是我当前的查看代码:
<label class="control-label" ng-class="{'margin-left:100px' : is_modal}">Hello</label>
Run Code Online (Sandbox Code Playgroud)
is_modal只是一个标志,我需要时在控制器中切换到true/false.
上面的代码不起作用,我也尝试过:
<label class="control-label" ng-class="{'style=margin-left:100px' : is_modal}">Hello</label>
Run Code Online (Sandbox Code Playgroud)
但也不起作用.谁知道这是否可能?要定义内联样式?
另一种选择是ng-style,但我似乎无法将我的控制器标志is_modal绑定到ng-style,因为它不允许像ng-class那样询问条件...
谢谢亚历杭德罗