pythoniphonereactjstornadotornado-motor

Python Tornado rest API calls not rendering to mobile


API results render to desktop but not to my iPhone. So I have a simple rest API that I'm making the calls from a ReactJS front end. I'm using axios after having a LOT of troubles with superagent. I'm not getting any errors in any browser console, desktop or mobile(been using jsconsole to debug my iphone 5). Yet on my Python Tornado back end it's throwing a few errors for both desktop and mobile:

1st:

tornado.application:Uncaught exception GET

2nd:

ERROR:tornado.general:Cannot send error response after headers written ERROR:tornado.general:Failed to flush partial response

3rd:

During handling of the above exception, another exception occurred:

and this can be found as the error happening in my Python env files

TypeError: 'str' object is not callable

none of this crashes the script/app... Here's my ReactJS/Javascript using axios:

componentDidMount() {
    console.log('componentDidMount');

    const url = 'http://127.0.0.1:3000/api/generator';
    axios.get(url).then((response) => {
        const results = response.data
        console.log(JSON.stringify(results.data))
        this.setState({data: results.powergen})
    })
}

render() {
    const powergenName = this.state.data.map((powergen, i) => {
        const pgBrand = new RegExp(this.state.brandSelected)
        console.log(this.state.brandSelected)
        if (pgBrand.test(powergen.name)) {
            return <div className="row" key={i}><br/>
                <Card style={{
                    width: '250px'
                }}>
                    <CardTitle title={powergen.price} subtitle={powergen.model}/>
                    <CardTitle title={powergen.name} subtitle={powergen.deal}/>
                </Card>
            </div>
        } else
            return false
    })
    return (
        <div>
            <Dropdown source={this.brands} onChange={this.handleBrandChange} value={this.state.brandSelected}/>
            <div>{powergenName}</div>
        </div>
    )
}

and here's my Python Tornado bit:

class PowgenHandler(tornado.web.RequestHandler):

def send_error(self, status_code=500, **kwargs):
    """
    Generates the custom HTTP error.And always return 200 code.
    """
    reason = None
    if 'exc_info' in kwargs:
        exception = kwargs['exc_info'][1]
        if isinstance(exception, HTTPError) and exception.reason:
            reason = exception.reason
    try:
        msg = reason if reason else httputil.responses[status_code]
    except KeyError:
        msg = "unkown error"

    result = {"status_code":status_code, "reason": msg}

    self.clear()
    self.set_header("Content-Type", "application/json")
    self.set_status(200)
    self.write(tornado.escape.json_encode(result))
    self.finish()

def set_default_headers(self):
    print("setting headers!!!")
    self.set_header("Access-Control-Allow-Origin", '*')
    self.set_header("Access-Control-Allow-Headers", 'Content-Type')
    self.set_header('Access-Control-Allow-Methods', 'GET')
    self.set_header('Access-Control-Allow-Credentials', 'None')

async def get(self):
    output = []
    gn = db.generators.find()
    for gens in (await gn.to_list(length=1000)):
        output.append({'name': gens['name'],
                       'model': gens['model'],
                       'price': gens['price'],
                       'deal': gens['deal'],
                       'image': gens['image'],
                       'id': gens['gen_id']})
    self.write(json.dumps({'powergen': output}))
    self.finish()

It's pretty straight forward so I'm not getting why it's not working on my iPhone. I guess I should also mention that I'm using Motor for MongoDB async which is why that async & await are there. Other than that, I did remove all the styling & react-toolbox stuff just to make sure it wasn't rendering because of that and it didn't make a difference.

I know there's something maybe a bunch of things I'm not doing but I can't figure out what that is as Google searching any of the errors only comes back with less than 5 relevant results. Any input would be greatly appreciated. Thanks!

oh - here's a link to my GitHub repo for it if you want/need to see the entire project. Thanks again! Tornado-Pricer

EDIT:

Here is what I get in my console: Python Tornado errors


Solution

  • I'm marking this as solved as there aren't any errors to work off of so it's just down to debugging whatever is causing the issue of not rendering to mobile.