我一直在尝试使用Python请求来使用Twitter Streaming API.
文档中有一个简单的例子:
import requests
import json
r = requests.post('https://stream.twitter.com/1/statuses/filter.json',
data={'track': 'requests'}, auth=('username', 'password'))
for line in r.iter_lines():
if line: # filter out keep-alive new lines
print json.loads(line)
Run Code Online (Sandbox Code Playgroud)
执行此操作时,调用requests.post()
永不返回.我已经进行了实验并证明它肯定会连接到Twitter并从API接收数据.但是,它不是返回响应对象,而是在那里消耗尽可能多的数据,就像Twitter发送的一样多.从上面的代码判断,我希望requests.post()
返回一个与Twitter打开连接的响应对象,我可以继续接收实时结果.
(为了证明它正在接收数据,我使用另一个shell中的相同凭据连接到Twitter,于是Twitter关闭了第一个连接,并且该调用返回了响应对象.该r.content
属性包含连接打开时收到的所有备份数据. )
该文档未提及requests.post
在使用所有提供的数据之前导致返回所需的任何其他步骤.其他人似乎使用类似的代码而没有遇到这个问题,例如这里.
我正在使用:
在简单的继承树中,抽象超类有两个子类.
子类都存储一个键值对,但是其中一个将保存一个类型的加密字符串,另一个将保存一个普通的旧字符串.
现在,我的问题是我可以这样做:
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public abstract Attribute {
@Id
private Integer id;
@Column(name="attribute_key")
private String key;
}
@Entity
public EncryptedAttribute extends Attribute {
@Column(name="attribute_value")
private EncryptedString encryptedValue;
}
@Entity
public UnEncryptedAttribute extends Attribute {
@Column(name="attribute_value")
private String plainValue;
}
Run Code Online (Sandbox Code Playgroud)
Encrypted String和plain String最终都应该作为db中的varchars,但是我可以在同一列中存储与不同子类关联的持久属性吗?这将避免在未在特定行中使用的列中存储空值的"瑞士奶酪"副作用.