将带有许多键的python字典插入Postgres数据库而不必枚举所有键的最佳方法是什么?
我想做点什么......
song = dict()
song['title'] = 'song 1'
song['artist'] = 'artist 1'
...
cursor.execute('INSERT INTO song_table (song.keys()) VALUES (song)')
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Angular $ http和以下代码进行跨源POST请求.
//I've tried setting and removing these http config options
$http.defaults.useXDomain = true;
delete $http.defaults.headers.common['X-Requested-With'];
$http.defaults.headers.common['Content-Type'] = 'application/x-www-form-urlencoded';
//Basic request, with some private headers removed
return $http({
method: 'POST',
//withCredentials:true,
headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'},
params: params,
url: url
});
Run Code Online (Sandbox Code Playgroud)
预检OPTIONS请求获取200 OK
,但后续POST收到400 Bad Request
响应.查看Chrome调试窗口中的跟踪,我没有看到Content-Type: application/x-www-form-urlencoded; charset=UTF-8
POST 的标题.我假设这就是服务器返回错误请求响应的原因.
我正在设置一些我从上面的代码中省略的其他自定义标题,并且它们正在被发送并显示正常.
我还要提一下,我可以使用Chrome的Advanced Rest Client应用程序发出此请求并收到正确的回复.(访问令牌)
我也试过做一个直接的XMLHttpRequest(),但我得到了同样的错误.
有关为什么我的Content-Type标头没有被设置的任何见解?
我已经看到了如何从ISO格式化日期,如2007-01-14T20:34:22+00:00
使用python更加可读的格式datetime
.
有一种简单的方法来生成一个随机ISO8601日期类似于这个答案的datetime
字符串?
python ×2
angularjs ×1
cors ×1
datetime ×1
http-headers ×1
iso8601 ×1
postgresql ×1
psycopg2 ×1