小编u8y*_*541的帖子

Python print语句"语法错误:语法无效"

为什么Python print在第9行的简单语句中给出了语法错误?

import hashlib, sys
m = hashlib.md5()
hash = ""
hash_file = raw_input("What is the file name in which the hash resides?  ")
wordlist = raw_input("What is your wordlist?  (Enter the file name)  ")
try:
    hashdocument = open(hash_file,"r")
except IOError:
    print "Invalid file."    # Syntax error: invalid syntax
    raw_input()
    sys.exit()
else:
    hash = hashdocument.readline()
    hash = hash.replace("\n","")
Run Code Online (Sandbox Code Playgroud)

Python的版本是:

Python 3.2.2 (default, Sep  4 2011, 09:07:29) [MSC v.1500 64 bit (AMD64)] on win
32
Run Code Online (Sandbox Code Playgroud)

python syntax syntax-error python-3.x

50
推荐指数
2
解决办法
19万
查看次数

在获取请求中设置Content-Type不起作用

我正在对服务器执行远程获取请求。有效负载为JSON格式,因此我想将Content-Type标头更改为application/json。我已使用以下代码执行此操作:

let email = document.getElementById("email").value
let password = document.getElementById("password").value

const body = {"email":email, "password":password}
const headers = new Headers({
    "Content-Type": "application/json",
    "Content-Length": JSON.stringify(body).length
})
const options = {
    method: "POST",
    mode: "no-cors",
    headers: headers,
    body: JSON.stringify(body)
}
console.log(options)
const response = await fetch('http://xx.xx.xx.xxx/login', options)
const json = await response.json()
console.log(json)
Run Code Online (Sandbox Code Playgroud)

但是,在Chrome开发者工具控制台中,Content-Type请求的标头仍为text/plain;charset=UTF-8。我究竟做错了什么?

javascript json reactjs fetch-api

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