Home > Net >  string index out of range? in django post request
string index out of range? in django post request

Time:02-14

I'm getting error string index out of range when I getting simple text from post request and want to show data in array.

[["daveen brewster 218 tokay drive \u25aa fayetteville nc 28301 \u25aa 910 527 2739 email [email protected] professional profile customer service orient professional with healthcare industry experience accustom to work in environment where accuracy and accountability be essential consistently model and inspire high level of integrity follow policy procedure and guideline to assure consistent quality \u25aa \u25aa \u25aa adaptable adapt to change situation and expectation and accept new idea and concept time management manage time and priority to meet goal deadline and objective problem solver identify and define a problem generate solution and determine appropriate strategy microsoft office application word excel outlook and powerpoint key qualification medical administrative assistant \u25aa medical terminology \u25aa medical transcription patient processing \u25aa patient registration \u25aa medical record management \u25aa check in \u25aa check out \u25aa datum entry release of information \u25aa hipaa compliance \u25aa medical law ethic \u25aa cms 1500 claim form \u25aa billing cycle claim appeal process \u25aa medical billing knowledge \u25aa third party billing \u25aa medicare \u25aa medicaid \u25aa hmo \u25aa ppo basic code skill for icd-10 cpt \u25aa insurance verification \u25aa anatomy physiology education ultimate medical academy \u2502 associate of science degree health science medical administrative assistant 2021 ultimate medical academy \u2502 hipaa essential for healthcare professional certificate north carolina department of health and human service | nurse aide 1 training professional experience alorica irvin ca 10/2020 present customer service representative temporarily remote call center \u25aa receive inbound phone call and interact with customer to resolve question and concern \u25aa track call relate information maintain and update account and cancel policy \u25aa enroll prospective customer in insurance policy blue cross blue shield humana aetna \u25aa utilize webrtc and vmware system add payment information on customer account and transfer to billing department to process payment private duty care fayetteville nc 01/2016 01/2019 inman home health care fayetteville nc 05/2007 02/2013 certify nursing assistant \u25aa assist with activity of daily living personal hygiene mobility and feeding \u25aa take and record vital sign and perform service in a timely and professional manner \u25aa document and report change in patient habit condition and activity \u25aa help patient with medication and monitor change in behavior \u25aa schedule appointment for patient transport to and from appoin tment and communicate with doctor additional professional experience include 1   year of experience as a patient care liaison certify nursing assistant kitchen manager volunteer experience alive ministry fayetteville nc youth counselor \u25aa assist youth with schoolwork and personal issue \u25aa facilitated trip and assist with college and job application 01/2004 01/2020 \u25aa maintain positive attitude show respect to all those with whom there be contact while perform duty", {"entities": [[667, 685, "SKILL"], [686, 690, "SKILL"], [746, 760, "SKILL"], [795, 816, "SKILL"], [838, 858, "SKILL"], [949, 965, "SKILL"], [1075, 1094, "SKILL"], [1108, 1116, "SKILL"], [1135, 1139, "SKILL"], [1150, 1156, "SKILL"], [1157, 1160, "SKILL"], [1163, 1185, "SKILL"], [1188, 1195, "SKILL"], [1196, 1206, "SKILL"], [1746, 1753, "SKILL"], [1868, 1874, "SKILL"], [2104, 2111, "SKILL"], [2170, 2177, "SKILL"], [2178, 2186, "SKILL"]]}]]

when i run this query in jupyter notebook then working fine and getting data from this array but when i getting with the help of post request in django and getting in views then getting string index out of range This is code which I'm using.

<form action="{% url 'text_extracted' %}" method="POST">
                        {% csrf_token %}
                        <div >
                            <label for="comment">Json:</label>
                            <textarea  rows="10" id="json_text" name="json_text" required></textarea>
                        </div>
                        <input type="submit" >
                    </form>
def text_extracted(request):

    if request.method == 'POST':
        json_text = request.POST['json_text']
        for span in json_text:
            for ent in span[1]['entities']:
                print(json_text[0][0][ent[0]:ent[1]])
                
    return HttpResponse("Ok")

Update: I'm getting this in request print(request.POST['json_text'])

[
        ["daveen brewster 218 tokay drive \u25aa fayetteville nc 28301 \u25aa 910 527 2739 email [email protected] professional profile customer service orient professional with healthcare industry experience accustom to work in environment where accuracy and accountability be essential consistently model and inspire high level of integrity follow policy procedure and guideline to assure consistent quality \u25aa \u25aa \u25aa adaptable adapt to change situation and expectation and accept new idea and concept time management manage time and priority to meet goal deadline and objective problem solver identify and define a problem generate solution and determine appropriate strategy microsoft office application word excel outlook and powerpoint key qualification medical administrative assistant \u25aa medical terminology \u25aa medical transcription patient processing \u25aa patient registration \u25aa medical record management \u25aa check in \u25aa check out \u25aa datum entry release of information \u25aa hipaa compliance \u25aa medical law ethic \u25aa cms 1500 claim form \u25aa billing cycle claim appeal process \u25aa medical billing knowledge \u25aa third party billing \u25aa medicare \u25aa medicaid \u25aa hmo \u25aa ppo basic code skill for icd-10 cpt \u25aa insurance verification \u25aa anatomy physiology education ultimate medical academy \u2502 associate of science degree health science medical administrative assistant 2021 ultimate medical academy \u2502 hipaa essential for healthcare professional certificate north carolina department of health and human service | nurse aide 1 training professional experience alorica irvin ca 10/2020 present customer service representative temporarily remote call center \u25aa receive inbound phone call and interact with customer to resolve question and concern \u25aa track call relate information maintain and update account and cancel policy \u25aa enroll prospective customer in insurance policy blue cross blue shield humana aetna \u25aa utilize webrtc and vmware system add payment information on customer account and transfer to billing department to process payment private duty care fayetteville nc 01/2016 01/2019 inman home health care fayetteville nc 05/2007 02/2013 certify nursing assistant \u25aa assist with activity of daily living personal hygiene mobility and feeding \u25aa take and record vital sign and perform service in a timely and professional manner \u25aa document and report change in patient habit condition and activity \u25aa help patient with medication and monitor change in behavior \u25aa schedule appointment for patient transport to and from appoin tment and communicate with doctor additional professional experience include 1   year of experience as a patient care liaison certify nursing assistant kitchen manager volunteer experience alive ministry fayetteville nc youth counselor \u25aa assist youth with schoolwork and personal issue \u25aa facilitated trip and assist with college and job application 01/2004 01/2020 \u25aa maintain positive attitude show respect to all those with whom there be contact while perform duty", {
                "entities": [
                        [667, 685, "SKILL"],
                        [686, 690, "SKILL"],
                        [746, 760, "SKILL"],
                        [795, 816, "SKILL"],
                        [838, 858, "SKILL"],
                        [949, 965, "SKILL"],
                        [1075, 1094, "SKILL"],
                        [1108, 1116, "SKILL"],
                        [1135, 1139, "SKILL"],
                        [1150, 1156, "SKILL"],
                        [1157, 1160, "SKILL"],
                        [1163, 1185, "SKILL"],
                        [1188, 1195, "SKILL"],
                        [1196, 1206, "SKILL"],
                        [1746, 1753, "SKILL"],
                        [1868, 1874, "SKILL"],
                        [2104, 2111, "SKILL"],
                        [2170, 2177, "SKILL"],
                        [2178, 2186, "SKILL"]
                ]
        }]
]

CodePudding user response:

I believe the response is coming back in plain text and not a ready to use dictionary. Try the following using json.loads:

def text_extracted(request):
    import json
    if request.method == 'POST':
        json_text = json.loads(request.POST['json_text'])
        for span in json_text:
            for ent in span[1]['entities']:
                print(json_text[0][0][ent[0]:ent[1]])
                
    return HttpResponse("Ok")
  • Related