Python API Output is not getting formatted in ReactJS












0














Below is my ReactJS component written where I want to print the output as list of buttons.






// CityContent.js

import React, { Component } from "react";
import axios from "axios";

const pStyle = {
backgroundColor: "#79D3EF",
color: "white"
};

export default class CityContent extends Component {
constructor(props) {
super(props);

this.state = {
citydetail:
};
}

componentDidMount() {
axios.get("http://127.0.0.1:8000/Delhi").then(res => {
const citydetail = res.data;
this.setState({ citydetail });
});
}

render() {
console.log(this.state);
return (
<div className="content-wrapper">
<section className="content-header">
<div className="row">
<div className="col-md-4">
<div className="box">
<div className="box-body">
<div className="row">
<div className="col-md-8">
<ul>
{this.state.citydetail.map(city => (
<li>
{city.name}
<button>{city.name}</button>
</li>
))}
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
</div>
);
}
}





The Api used is written in python Boto which returns the list of instances whose code is as follows:






import boto3
import json

Cities = {'Delhi': 'LB1',
'Hyderabad': 'LB2', 'Mumbai': 'LB3'}


def CityDetail(city):
client = boto3.client('elb')
response = client.describe_instance_health(
LoadBalancerName=Cities[city]
)
Instances = dict()
InstanceList = list()
for goods in response['InstanceStates']:
InstanceList.append({"name": goods['InstanceId']})
print(InstanceList)





Api is returning output as :



   [{'name': 'i-cc608f4d'}, {'name': 'i-fd608f7c'}, {'name': 'i-fe608f7f'}]


I want these IDs to be printed as buttons one below other in ReactJS component.



In the current code when ran doesn't show anything on screen and returns this.state.citydetail.map is not a function on chrome console.










share|improve this question




















  • 1




    what is the Content-Type of the response?
    – Fazal Rasel
    Nov 14 '18 at 10:13










  • It's showing array in console
    – Saurabh Kumar
    Nov 14 '18 at 10:29










  • If data type is array on browser console (not python console) and no error on browser console, then check your CSS rules.
    – Fazal Rasel
    Nov 14 '18 at 10:40










  • There's an error , on console it is showing: CityContent.jsx?a1a1:44 Uncaught (in promise) TypeError: this.state.citydetail.map is not a function
    – Saurabh Kumar
    Nov 14 '18 at 10:51












  • Hit this url directly in browser, what do you see in source (Ctrl + U) 127.0.0.1:8000/Delhi
    – kiranvj
    Nov 14 '18 at 13:56
















0














Below is my ReactJS component written where I want to print the output as list of buttons.






// CityContent.js

import React, { Component } from "react";
import axios from "axios";

const pStyle = {
backgroundColor: "#79D3EF",
color: "white"
};

export default class CityContent extends Component {
constructor(props) {
super(props);

this.state = {
citydetail:
};
}

componentDidMount() {
axios.get("http://127.0.0.1:8000/Delhi").then(res => {
const citydetail = res.data;
this.setState({ citydetail });
});
}

render() {
console.log(this.state);
return (
<div className="content-wrapper">
<section className="content-header">
<div className="row">
<div className="col-md-4">
<div className="box">
<div className="box-body">
<div className="row">
<div className="col-md-8">
<ul>
{this.state.citydetail.map(city => (
<li>
{city.name}
<button>{city.name}</button>
</li>
))}
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
</div>
);
}
}





The Api used is written in python Boto which returns the list of instances whose code is as follows:






import boto3
import json

Cities = {'Delhi': 'LB1',
'Hyderabad': 'LB2', 'Mumbai': 'LB3'}


def CityDetail(city):
client = boto3.client('elb')
response = client.describe_instance_health(
LoadBalancerName=Cities[city]
)
Instances = dict()
InstanceList = list()
for goods in response['InstanceStates']:
InstanceList.append({"name": goods['InstanceId']})
print(InstanceList)





Api is returning output as :



   [{'name': 'i-cc608f4d'}, {'name': 'i-fd608f7c'}, {'name': 'i-fe608f7f'}]


I want these IDs to be printed as buttons one below other in ReactJS component.



In the current code when ran doesn't show anything on screen and returns this.state.citydetail.map is not a function on chrome console.










share|improve this question




















  • 1




    what is the Content-Type of the response?
    – Fazal Rasel
    Nov 14 '18 at 10:13










  • It's showing array in console
    – Saurabh Kumar
    Nov 14 '18 at 10:29










  • If data type is array on browser console (not python console) and no error on browser console, then check your CSS rules.
    – Fazal Rasel
    Nov 14 '18 at 10:40










  • There's an error , on console it is showing: CityContent.jsx?a1a1:44 Uncaught (in promise) TypeError: this.state.citydetail.map is not a function
    – Saurabh Kumar
    Nov 14 '18 at 10:51












  • Hit this url directly in browser, what do you see in source (Ctrl + U) 127.0.0.1:8000/Delhi
    – kiranvj
    Nov 14 '18 at 13:56














0












0








0







Below is my ReactJS component written where I want to print the output as list of buttons.






// CityContent.js

import React, { Component } from "react";
import axios from "axios";

const pStyle = {
backgroundColor: "#79D3EF",
color: "white"
};

export default class CityContent extends Component {
constructor(props) {
super(props);

this.state = {
citydetail:
};
}

componentDidMount() {
axios.get("http://127.0.0.1:8000/Delhi").then(res => {
const citydetail = res.data;
this.setState({ citydetail });
});
}

render() {
console.log(this.state);
return (
<div className="content-wrapper">
<section className="content-header">
<div className="row">
<div className="col-md-4">
<div className="box">
<div className="box-body">
<div className="row">
<div className="col-md-8">
<ul>
{this.state.citydetail.map(city => (
<li>
{city.name}
<button>{city.name}</button>
</li>
))}
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
</div>
);
}
}





The Api used is written in python Boto which returns the list of instances whose code is as follows:






import boto3
import json

Cities = {'Delhi': 'LB1',
'Hyderabad': 'LB2', 'Mumbai': 'LB3'}


def CityDetail(city):
client = boto3.client('elb')
response = client.describe_instance_health(
LoadBalancerName=Cities[city]
)
Instances = dict()
InstanceList = list()
for goods in response['InstanceStates']:
InstanceList.append({"name": goods['InstanceId']})
print(InstanceList)





Api is returning output as :



   [{'name': 'i-cc608f4d'}, {'name': 'i-fd608f7c'}, {'name': 'i-fe608f7f'}]


I want these IDs to be printed as buttons one below other in ReactJS component.



In the current code when ran doesn't show anything on screen and returns this.state.citydetail.map is not a function on chrome console.










share|improve this question















Below is my ReactJS component written where I want to print the output as list of buttons.






// CityContent.js

import React, { Component } from "react";
import axios from "axios";

const pStyle = {
backgroundColor: "#79D3EF",
color: "white"
};

export default class CityContent extends Component {
constructor(props) {
super(props);

this.state = {
citydetail:
};
}

componentDidMount() {
axios.get("http://127.0.0.1:8000/Delhi").then(res => {
const citydetail = res.data;
this.setState({ citydetail });
});
}

render() {
console.log(this.state);
return (
<div className="content-wrapper">
<section className="content-header">
<div className="row">
<div className="col-md-4">
<div className="box">
<div className="box-body">
<div className="row">
<div className="col-md-8">
<ul>
{this.state.citydetail.map(city => (
<li>
{city.name}
<button>{city.name}</button>
</li>
))}
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
</div>
);
}
}





The Api used is written in python Boto which returns the list of instances whose code is as follows:






import boto3
import json

Cities = {'Delhi': 'LB1',
'Hyderabad': 'LB2', 'Mumbai': 'LB3'}


def CityDetail(city):
client = boto3.client('elb')
response = client.describe_instance_health(
LoadBalancerName=Cities[city]
)
Instances = dict()
InstanceList = list()
for goods in response['InstanceStates']:
InstanceList.append({"name": goods['InstanceId']})
print(InstanceList)





Api is returning output as :



   [{'name': 'i-cc608f4d'}, {'name': 'i-fd608f7c'}, {'name': 'i-fe608f7f'}]


I want these IDs to be printed as buttons one below other in ReactJS component.



In the current code when ran doesn't show anything on screen and returns this.state.citydetail.map is not a function on chrome console.






// CityContent.js

import React, { Component } from "react";
import axios from "axios";

const pStyle = {
backgroundColor: "#79D3EF",
color: "white"
};

export default class CityContent extends Component {
constructor(props) {
super(props);

this.state = {
citydetail:
};
}

componentDidMount() {
axios.get("http://127.0.0.1:8000/Delhi").then(res => {
const citydetail = res.data;
this.setState({ citydetail });
});
}

render() {
console.log(this.state);
return (
<div className="content-wrapper">
<section className="content-header">
<div className="row">
<div className="col-md-4">
<div className="box">
<div className="box-body">
<div className="row">
<div className="col-md-8">
<ul>
{this.state.citydetail.map(city => (
<li>
{city.name}
<button>{city.name}</button>
</li>
))}
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
</div>
);
}
}





// CityContent.js

import React, { Component } from "react";
import axios from "axios";

const pStyle = {
backgroundColor: "#79D3EF",
color: "white"
};

export default class CityContent extends Component {
constructor(props) {
super(props);

this.state = {
citydetail:
};
}

componentDidMount() {
axios.get("http://127.0.0.1:8000/Delhi").then(res => {
const citydetail = res.data;
this.setState({ citydetail });
});
}

render() {
console.log(this.state);
return (
<div className="content-wrapper">
<section className="content-header">
<div className="row">
<div className="col-md-4">
<div className="box">
<div className="box-body">
<div className="row">
<div className="col-md-8">
<ul>
{this.state.citydetail.map(city => (
<li>
{city.name}
<button>{city.name}</button>
</li>
))}
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
</div>
);
}
}





import boto3
import json

Cities = {'Delhi': 'LB1',
'Hyderabad': 'LB2', 'Mumbai': 'LB3'}


def CityDetail(city):
client = boto3.client('elb')
response = client.describe_instance_health(
LoadBalancerName=Cities[city]
)
Instances = dict()
InstanceList = list()
for goods in response['InstanceStates']:
InstanceList.append({"name": goods['InstanceId']})
print(InstanceList)





import boto3
import json

Cities = {'Delhi': 'LB1',
'Hyderabad': 'LB2', 'Mumbai': 'LB3'}


def CityDetail(city):
client = boto3.client('elb')
response = client.describe_instance_health(
LoadBalancerName=Cities[city]
)
Instances = dict()
InstanceList = list()
for goods in response['InstanceStates']:
InstanceList.append({"name": goods['InstanceId']})
print(InstanceList)






reactjs






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 10:17









Hemadri Dasari

7,38411239




7,38411239










asked Nov 14 '18 at 9:59









Saurabh Kumar

135




135








  • 1




    what is the Content-Type of the response?
    – Fazal Rasel
    Nov 14 '18 at 10:13










  • It's showing array in console
    – Saurabh Kumar
    Nov 14 '18 at 10:29










  • If data type is array on browser console (not python console) and no error on browser console, then check your CSS rules.
    – Fazal Rasel
    Nov 14 '18 at 10:40










  • There's an error , on console it is showing: CityContent.jsx?a1a1:44 Uncaught (in promise) TypeError: this.state.citydetail.map is not a function
    – Saurabh Kumar
    Nov 14 '18 at 10:51












  • Hit this url directly in browser, what do you see in source (Ctrl + U) 127.0.0.1:8000/Delhi
    – kiranvj
    Nov 14 '18 at 13:56














  • 1




    what is the Content-Type of the response?
    – Fazal Rasel
    Nov 14 '18 at 10:13










  • It's showing array in console
    – Saurabh Kumar
    Nov 14 '18 at 10:29










  • If data type is array on browser console (not python console) and no error on browser console, then check your CSS rules.
    – Fazal Rasel
    Nov 14 '18 at 10:40










  • There's an error , on console it is showing: CityContent.jsx?a1a1:44 Uncaught (in promise) TypeError: this.state.citydetail.map is not a function
    – Saurabh Kumar
    Nov 14 '18 at 10:51












  • Hit this url directly in browser, what do you see in source (Ctrl + U) 127.0.0.1:8000/Delhi
    – kiranvj
    Nov 14 '18 at 13:56








1




1




what is the Content-Type of the response?
– Fazal Rasel
Nov 14 '18 at 10:13




what is the Content-Type of the response?
– Fazal Rasel
Nov 14 '18 at 10:13












It's showing array in console
– Saurabh Kumar
Nov 14 '18 at 10:29




It's showing array in console
– Saurabh Kumar
Nov 14 '18 at 10:29












If data type is array on browser console (not python console) and no error on browser console, then check your CSS rules.
– Fazal Rasel
Nov 14 '18 at 10:40




If data type is array on browser console (not python console) and no error on browser console, then check your CSS rules.
– Fazal Rasel
Nov 14 '18 at 10:40












There's an error , on console it is showing: CityContent.jsx?a1a1:44 Uncaught (in promise) TypeError: this.state.citydetail.map is not a function
– Saurabh Kumar
Nov 14 '18 at 10:51






There's an error , on console it is showing: CityContent.jsx?a1a1:44 Uncaught (in promise) TypeError: this.state.citydetail.map is not a function
– Saurabh Kumar
Nov 14 '18 at 10:51














Hit this url directly in browser, what do you see in source (Ctrl + U) 127.0.0.1:8000/Delhi
– kiranvj
Nov 14 '18 at 13:56




Hit this url directly in browser, what do you see in source (Ctrl + U) 127.0.0.1:8000/Delhi
– kiranvj
Nov 14 '18 at 13:56












1 Answer
1






active

oldest

votes


















0














Looks like Python server is not responding with JSON - try this:



Instances = dict()
InstanceList = list()
for goods in response['InstanceStates']:
InstanceList.append({"name": goods['InstanceId']})
json_str = json.dumps(InstanceList)
print(json_str)





share|improve this answer























  • CityContent.jsx?a1a1:44 Uncaught (in promise) TypeError: this.state.citydetail.map is not a function . I'm getting above error in ReactJS component
    – Saurabh Kumar
    Nov 14 '18 at 10:47










  • Making above change made my output like this: [{"name": "i-cc608f4d"}, {"name": "i-fd608f7c"}, {"name": "i-fe608f7f"}]
    – Saurabh Kumar
    Nov 14 '18 at 11:01












  • That suggests this.state.citydetail is not an array. My guess is that response from API is not of content-type json. What does network tab in chrome dev tools say ? Did you try code from my answer ? Please add a debug to your get method and check the console axios.get("http://127.0.0.1:8000/Delhi").then(res => { console.log('data', res.data); console.log('status', res.status); const citydetail = res.data; this.setState({ citydetail }); });
    – MrAleister
    Nov 14 '18 at 11:03












  • I've used your code, and I can see below snippet in chrome console logs : data {status: "[{"name": "i-cc608f4d"}, {"name": "i-fd608f7c"}, {"name": "i-fe608f7f"}]"} CityContent.jsx?a1a1:27
    – Saurabh Kumar
    Nov 14 '18 at 11:13












  • But still the " TypeError: this.state.citydetail.map is not a function" is there is logs. I believe I'm having issue with this function call in render method, not sure how to fix that in above code
    – Saurabh Kumar
    Nov 14 '18 at 11:16











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53297439%2fpython-api-output-is-not-getting-formatted-in-reactjs%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Looks like Python server is not responding with JSON - try this:



Instances = dict()
InstanceList = list()
for goods in response['InstanceStates']:
InstanceList.append({"name": goods['InstanceId']})
json_str = json.dumps(InstanceList)
print(json_str)





share|improve this answer























  • CityContent.jsx?a1a1:44 Uncaught (in promise) TypeError: this.state.citydetail.map is not a function . I'm getting above error in ReactJS component
    – Saurabh Kumar
    Nov 14 '18 at 10:47










  • Making above change made my output like this: [{"name": "i-cc608f4d"}, {"name": "i-fd608f7c"}, {"name": "i-fe608f7f"}]
    – Saurabh Kumar
    Nov 14 '18 at 11:01












  • That suggests this.state.citydetail is not an array. My guess is that response from API is not of content-type json. What does network tab in chrome dev tools say ? Did you try code from my answer ? Please add a debug to your get method and check the console axios.get("http://127.0.0.1:8000/Delhi").then(res => { console.log('data', res.data); console.log('status', res.status); const citydetail = res.data; this.setState({ citydetail }); });
    – MrAleister
    Nov 14 '18 at 11:03












  • I've used your code, and I can see below snippet in chrome console logs : data {status: "[{"name": "i-cc608f4d"}, {"name": "i-fd608f7c"}, {"name": "i-fe608f7f"}]"} CityContent.jsx?a1a1:27
    – Saurabh Kumar
    Nov 14 '18 at 11:13












  • But still the " TypeError: this.state.citydetail.map is not a function" is there is logs. I believe I'm having issue with this function call in render method, not sure how to fix that in above code
    – Saurabh Kumar
    Nov 14 '18 at 11:16
















0














Looks like Python server is not responding with JSON - try this:



Instances = dict()
InstanceList = list()
for goods in response['InstanceStates']:
InstanceList.append({"name": goods['InstanceId']})
json_str = json.dumps(InstanceList)
print(json_str)





share|improve this answer























  • CityContent.jsx?a1a1:44 Uncaught (in promise) TypeError: this.state.citydetail.map is not a function . I'm getting above error in ReactJS component
    – Saurabh Kumar
    Nov 14 '18 at 10:47










  • Making above change made my output like this: [{"name": "i-cc608f4d"}, {"name": "i-fd608f7c"}, {"name": "i-fe608f7f"}]
    – Saurabh Kumar
    Nov 14 '18 at 11:01












  • That suggests this.state.citydetail is not an array. My guess is that response from API is not of content-type json. What does network tab in chrome dev tools say ? Did you try code from my answer ? Please add a debug to your get method and check the console axios.get("http://127.0.0.1:8000/Delhi").then(res => { console.log('data', res.data); console.log('status', res.status); const citydetail = res.data; this.setState({ citydetail }); });
    – MrAleister
    Nov 14 '18 at 11:03












  • I've used your code, and I can see below snippet in chrome console logs : data {status: "[{"name": "i-cc608f4d"}, {"name": "i-fd608f7c"}, {"name": "i-fe608f7f"}]"} CityContent.jsx?a1a1:27
    – Saurabh Kumar
    Nov 14 '18 at 11:13












  • But still the " TypeError: this.state.citydetail.map is not a function" is there is logs. I believe I'm having issue with this function call in render method, not sure how to fix that in above code
    – Saurabh Kumar
    Nov 14 '18 at 11:16














0












0








0






Looks like Python server is not responding with JSON - try this:



Instances = dict()
InstanceList = list()
for goods in response['InstanceStates']:
InstanceList.append({"name": goods['InstanceId']})
json_str = json.dumps(InstanceList)
print(json_str)





share|improve this answer














Looks like Python server is not responding with JSON - try this:



Instances = dict()
InstanceList = list()
for goods in response['InstanceStates']:
InstanceList.append({"name": goods['InstanceId']})
json_str = json.dumps(InstanceList)
print(json_str)






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 14 '18 at 10:25

























answered Nov 14 '18 at 10:17









MrAleister

439210




439210












  • CityContent.jsx?a1a1:44 Uncaught (in promise) TypeError: this.state.citydetail.map is not a function . I'm getting above error in ReactJS component
    – Saurabh Kumar
    Nov 14 '18 at 10:47










  • Making above change made my output like this: [{"name": "i-cc608f4d"}, {"name": "i-fd608f7c"}, {"name": "i-fe608f7f"}]
    – Saurabh Kumar
    Nov 14 '18 at 11:01












  • That suggests this.state.citydetail is not an array. My guess is that response from API is not of content-type json. What does network tab in chrome dev tools say ? Did you try code from my answer ? Please add a debug to your get method and check the console axios.get("http://127.0.0.1:8000/Delhi").then(res => { console.log('data', res.data); console.log('status', res.status); const citydetail = res.data; this.setState({ citydetail }); });
    – MrAleister
    Nov 14 '18 at 11:03












  • I've used your code, and I can see below snippet in chrome console logs : data {status: "[{"name": "i-cc608f4d"}, {"name": "i-fd608f7c"}, {"name": "i-fe608f7f"}]"} CityContent.jsx?a1a1:27
    – Saurabh Kumar
    Nov 14 '18 at 11:13












  • But still the " TypeError: this.state.citydetail.map is not a function" is there is logs. I believe I'm having issue with this function call in render method, not sure how to fix that in above code
    – Saurabh Kumar
    Nov 14 '18 at 11:16


















  • CityContent.jsx?a1a1:44 Uncaught (in promise) TypeError: this.state.citydetail.map is not a function . I'm getting above error in ReactJS component
    – Saurabh Kumar
    Nov 14 '18 at 10:47










  • Making above change made my output like this: [{"name": "i-cc608f4d"}, {"name": "i-fd608f7c"}, {"name": "i-fe608f7f"}]
    – Saurabh Kumar
    Nov 14 '18 at 11:01












  • That suggests this.state.citydetail is not an array. My guess is that response from API is not of content-type json. What does network tab in chrome dev tools say ? Did you try code from my answer ? Please add a debug to your get method and check the console axios.get("http://127.0.0.1:8000/Delhi").then(res => { console.log('data', res.data); console.log('status', res.status); const citydetail = res.data; this.setState({ citydetail }); });
    – MrAleister
    Nov 14 '18 at 11:03












  • I've used your code, and I can see below snippet in chrome console logs : data {status: "[{"name": "i-cc608f4d"}, {"name": "i-fd608f7c"}, {"name": "i-fe608f7f"}]"} CityContent.jsx?a1a1:27
    – Saurabh Kumar
    Nov 14 '18 at 11:13












  • But still the " TypeError: this.state.citydetail.map is not a function" is there is logs. I believe I'm having issue with this function call in render method, not sure how to fix that in above code
    – Saurabh Kumar
    Nov 14 '18 at 11:16
















CityContent.jsx?a1a1:44 Uncaught (in promise) TypeError: this.state.citydetail.map is not a function . I'm getting above error in ReactJS component
– Saurabh Kumar
Nov 14 '18 at 10:47




CityContent.jsx?a1a1:44 Uncaught (in promise) TypeError: this.state.citydetail.map is not a function . I'm getting above error in ReactJS component
– Saurabh Kumar
Nov 14 '18 at 10:47












Making above change made my output like this: [{"name": "i-cc608f4d"}, {"name": "i-fd608f7c"}, {"name": "i-fe608f7f"}]
– Saurabh Kumar
Nov 14 '18 at 11:01






Making above change made my output like this: [{"name": "i-cc608f4d"}, {"name": "i-fd608f7c"}, {"name": "i-fe608f7f"}]
– Saurabh Kumar
Nov 14 '18 at 11:01














That suggests this.state.citydetail is not an array. My guess is that response from API is not of content-type json. What does network tab in chrome dev tools say ? Did you try code from my answer ? Please add a debug to your get method and check the console axios.get("http://127.0.0.1:8000/Delhi").then(res => { console.log('data', res.data); console.log('status', res.status); const citydetail = res.data; this.setState({ citydetail }); });
– MrAleister
Nov 14 '18 at 11:03






That suggests this.state.citydetail is not an array. My guess is that response from API is not of content-type json. What does network tab in chrome dev tools say ? Did you try code from my answer ? Please add a debug to your get method and check the console axios.get("http://127.0.0.1:8000/Delhi").then(res => { console.log('data', res.data); console.log('status', res.status); const citydetail = res.data; this.setState({ citydetail }); });
– MrAleister
Nov 14 '18 at 11:03














I've used your code, and I can see below snippet in chrome console logs : data {status: "[{"name": "i-cc608f4d"}, {"name": "i-fd608f7c"}, {"name": "i-fe608f7f"}]"} CityContent.jsx?a1a1:27
– Saurabh Kumar
Nov 14 '18 at 11:13






I've used your code, and I can see below snippet in chrome console logs : data {status: "[{"name": "i-cc608f4d"}, {"name": "i-fd608f7c"}, {"name": "i-fe608f7f"}]"} CityContent.jsx?a1a1:27
– Saurabh Kumar
Nov 14 '18 at 11:13














But still the " TypeError: this.state.citydetail.map is not a function" is there is logs. I believe I'm having issue with this function call in render method, not sure how to fix that in above code
– Saurabh Kumar
Nov 14 '18 at 11:16




But still the " TypeError: this.state.citydetail.map is not a function" is there is logs. I believe I'm having issue with this function call in render method, not sure how to fix that in above code
– Saurabh Kumar
Nov 14 '18 at 11:16


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53297439%2fpython-api-output-is-not-getting-formatted-in-reactjs%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

鏡平學校

ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

Why https connections are so slow when debugging (stepping over) in Java?