简体   繁体   中英

Python script (webpy) emitting http 500 error upon trying to open an existing file

So I'm not really sure of the issue here... Basically, as long as I use the live API I'm working with to get the data, everything works fine. But if I try to open an existing file with the SAME exact data in it (from a previous api call), I get an internal server error. Here is the codeblock that is causing issues:

    thisFile = os.path.join(__location__, '2014/' + npi + '_individual.json')

    # if the local cached copy exists, then load that, otherwise, connect to the API
    if os.path.isfile(thisFile):
        target2 = open(thisFile)
        content = json.loads(target2.read())
    else:
        req = urllib2.Request(url + '?database=nppes&npi=' + npi + '&apikey=' + apiKey)
        r = urllib2.urlopen(req)
        content = json.loads(r.read())

I believe I'm using webpy or web2py (I'm not sure if these are two separate things). Executing the script via WSGI on Apache2.4.

It was an unrelated matter. Basically, this was failing because... so on the first call, it was refining the data I got back from the API, and then storing that REFINED data in the json file.

So on the next load, the json file exists, and when it loads it, some things have been renamed in the refining process, and so the rest of the script doesn't know how to execute. Silly issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM