小编use*_*563的帖子

CSRF 验证失败。请求因 csrf_exempt 中止

我试图在我的视图中从另一个站点接收一个发布请求,但我在我的视图中收到此错误:

Forbidden <span>(403)
CSRF verification failed. Request aborted.

    Reason given for failure:
    CSRF cookie not set.
Run Code Online (Sandbox Code Playgroud)

这是我的观点:

@csrf_exempt
@requires_csrf_token
def notificacao(request):
    if request.method == 'POST':
        notification_code = request.POST['notificationCode']
        if notification_code:
            url = 'https://ws.pagseguro.uol.com.br/v2/transactions/notifications/' + notification_code + '?email=filipe.ferminiano@gmail.com' + '&token=token'
            r = requests.get(url)
            print r['status']
            if r['status']:
                b = teste(name = r['status'])
            else:
                b = teste(name = 'teste errado')
            b.save()
            print 'r ' + r
            return render(request, 'obrigado.html',{'code':notification_code})

        else:
            print 'notification code is null'
            b = teste(name = 'sem notification code') …
Run Code Online (Sandbox Code Playgroud)

python django

5
推荐指数
0
解决办法
972
查看次数

Docx库无法识别Document方法

我正在尝试使用docx库,但是我收到了这个错误:

AttributeError: 'module' object has no attribute 'Document'
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

import docx
document = docx.Document('file.docx')
Run Code Online (Sandbox Code Playgroud)

怎么了?我已在其他计算机上使用过文档.我使用pip安装了docx库:

pip install docx
Run Code Online (Sandbox Code Playgroud)

python

5
推荐指数
1
解决办法
2414
查看次数

编解码器无法编码字符:字符映射到<undefined>

我尝试使用以下代码在python 2.7中读取docx文件:

import docx
document = docx.Document('sim_dir_administrativo.docx')
    docText = '\n\n'.join([
        paragraph.text.encode('utf-8') for paragraph in document.paragraphs])
Run Code Online (Sandbox Code Playgroud)

然后我尝试使用此代码解码文件中的字符串,因为我有一些特殊字符(例如ã):

print docText.decode("utf-8")
Run Code Online (Sandbox Code Playgroud)

但是,我收到了这个错误:

    return codecs.charmap_encode(input,errors,encoding_map)
UnicodeEncodeError: 'charmap' codec can't encode character u'\u2013' in position
 494457: character maps to <undefined>
Run Code Online (Sandbox Code Playgroud)

我怎么解决这个问题?

python

4
推荐指数
1
解决办法
9269
查看次数

用计数重塑数据

我有一个数据集,我想用R中的包reshape2重塑它,但是我收到了这个错误:

Aggregation function missing: defaulting to length
Run Code Online (Sandbox Code Playgroud)

这是我的数据的head():

cat_one customer valor
cama        A     1
cama        B     1
cama        C     1
mesa        D     1
mesa        A     1
mesa        A     1
Run Code Online (Sandbox Code Playgroud)

我希望像这样重塑它,并在两个变量之间进行计数:

customer     cama    mesa
A             1       0
B             2      ...
C
D            ...     ...
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

dcast(dados_teste, cat_one ~ customer, value.var = 'valor')
Run Code Online (Sandbox Code Playgroud)

我正在关注这个问题,但同样的解决方案并不适用于我.

r reshape2

3
推荐指数
1
解决办法
7223
查看次数

cbind返回因子向量的索引

我正在尝试使用以下代码连接2个向量,一个因子向量和一个字符向量:

results2 <- cbind(customer, result)
Run Code Online (Sandbox Code Playgroud)

问题是向量客户正在与行号连接,而不是客户因子的实际值.

它应该归还

customer result
10         a
22         b
25         a
Run Code Online (Sandbox Code Playgroud)

但相反它返回这个:

customer result
1         a
2         b
3         a
Run Code Online (Sandbox Code Playgroud)

r

1
推荐指数
1
解决办法
942
查看次数

标签 统计

python ×3

r ×2

django ×1

reshape2 ×1