Closed Keene-Chen closed 1 year ago
我看到解决办法了😅,后面有同样报错的同学可以尝试修改 #72 和 https://github.com/gangly/datafaker/issues/78#issuecomment-866712048 两处的方法,终于解决问题了😴
使用datafaker file e:\zm\home out1.txt 10 --meta meta.txt --format json
命令
meta.txt
文件内容如下:
id||int||自增id[:inc(id,1)] name||varchar(20)||学生名字[:name] school||varchar(20)||学校名字[:enum(清华大学,北京大学)] nickname||varchar(20)||学生小名[:enum(鬼泣, 高小王子, 歌神, 逗比)] age||int||学生年龄[:age] class_num||int||班级人数[:int(10, 100)] score||decimal(4,2)||成绩[:decimal(4,2,1)] phone||bigint||电话号码[:phone_number] email||varchar(64)||家庭网络邮箱[:email] ip||varchar(32)||IP地址[:ipv4] address||text||家庭地址[:address]
最后是生成的数据如下:
{"id": 1, "name": "杜梅", "school": "清华大学", "nickname": "高小王子", "age": 25, "class_num": 39, "score": 3.0, "phone": "18556570354", "email": "smo@gmail.com", "ip": "117.54.105.186", "address": "四川省成都市浔阳张街z座 710240"}
{"id": 2, "name": "陈淑英", "school": "清华大学", "nickname": "逗比", "age": 23, "class_num": 89, "score": 51.28, "phone": "13200140438", "email": "yonglai@jingli.cn", "ip": "198.51.59.108", "address": "上海市俊市新城兴城路C座 509477"}
D:>datafaker file D:\ out.txt 10 --meta meta.txt --format json Exception in thread Thread-2: Traceback (most recent call last): File "D:\dev\python\lib\threading.py", line 917, in _bootstrap_inner self.run() File "D:\dev\python\lib\threading.py", line 865, in run self._target(*self._args, **self._kwargs) File "D:\dev\python\lib\site-packages\datafaker\dbs\basedb.py", line 122, in save self.save_data(lines) File "D:\dev\python\lib\site-packages\datafaker\dbs\filedb.py", line 24, in save_data save2file(items, filepath) File "D:\dev\python\lib\site-packages\datafaker\utils.py", line 26, in save2file fp.writelines(items) UnicodeEncodeError: 'gbk' codec can't encode character '\u3dab' in position 41: illegal multibyte sequence
根据示例
datafaker file e:\zm\home out1.txt 10 --meta meta.txt --format json
报错然后我根据拉取请求 #72 修改
not in
逻辑后,可以正常生成json数据,但是生成的数据又是ASCII不是UTF-8。 希望给个提示,谢谢!生成数据如下: