Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x AvroTypeException:在python3中编写时_Python 3.x_Avro_Spark Avro_Avro Tools - Fatal编程技术网

Python 3.x AvroTypeException:在python3中编写时

Python 3.x AvroTypeException:在python3中编写时,python-3.x,avro,spark-avro,avro-tools,Python 3.x,Avro,Spark Avro,Avro Tools,我的avsc文件如下: {"type":"record", "namespace":"testing.avro", "name":"product", "aliases":["items","services","plans","deliverables"], "fields": [ {"name":"id", "type":"string" ,"aliases":["productid","itemid","item

我的avsc文件如下:

{"type":"record",
    "namespace":"testing.avro",
    "name":"product",
    "aliases":["items","services","plans","deliverables"],
    "fields":
        [   
            {"name":"id", "type":"string" ,"aliases":["productid","itemid","item","product"]},
            {"name":"brand", "type":"string","doc":"The brand associated", "default":"-1"},
            {"name":"category","type":{"type":"map","values":"string"},"doc":"the list of categoryId, categoryName associated, send Id as key, name as value" },
            {"name":"keywords", "type":{"type":"array","items":"string"},"doc":"this helps in long run in long run analysis, send the search keywords used for product"},
            {"name":"groupid", "type":["string","null"],"doc":"Use this to represent or flag value of group to which it belong, e.g. it may be variation of same product"},
            {"name":"price", "type":"double","aliases":["cost","unitprice"]},
            {"name":"unit", "type":"string", "default":"Each"},
            {"name":"unittype", "type":"string","aliases":["UOM"], "default":"Each"},
            {"name":"url", "type":["string","null"],"doc":"URL of the product to return for more details on product, this will be used for event analysis. Provide full url"},
            {"name":"imageurl","type":["string","null"],"doc":"Image url to display for return values"},
            {"name":"updatedtime", "type":"string"},
            {"name":"currency","type":"string", "default":"INR"},
            {"name":"image", "type":["bytes","null"] , "doc":"fallback in case we cant provide the image url, use this judiciously and limit size"},
            {"name":"features","type":{"type":"map","values":"string"},"doc":"Pass your classification attributes as features in key-value pair"}

        ]}
我能够解析这个,但当我试着这样写的时候,我总是遇到问题。我错过了什么?这是python3。我也验证了它是格式良好的json

from avro import schema as sc
from avro import datafile as df
from avro import io as avio
import os

_prodschema = 'product.avsc'
_namespace = 'testing.avro'

dirname =  os.path.dirname(__file__)
avroschemaname = os.path.join( os.path.dirname(__file__),_prodschema)
sch = {}

with open(avroschemaname,'r') as f:
    sch= f.read().encode(encoding='utf-8')
    f.close()


proschema = sc.Parse(sch)

print("Schema processed")
writer =  df.DataFileWriter(open(os.path.join(dirname,"products.json"),'wb'),
                             avio.DatumWriter(),proschema)
print("Just about to append the json")


writer.append({ "id":"23232",
            "brand":"Relaxo",
            "category":[{"123":"shoe","122":"accessories"}],
            "keywords":["relaxo","shoe"],
            "groupid":"",
            "price":"799.99",
            "unit":"Each",
            "unittype":"Each",
            "url":"",
            "imageurl":"",
            "updatedtime": "03/23/2017",
            "currency":"INR",
            "image":"",
            "features":[{"color":"black","size":"10","style":"contemperory"}]
            })
writer.close()
我错过了什么