Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7658551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:13:00+00:00 2026-05-31T13:13:00+00:00

I am calling the linkedin API and using json.loads to convert the JSON objects

  • 0

I am calling the linkedin API and using json.loads to convert the JSON objects to Python lists and dicts. Sometimes for certain LinkedIn profiles, they are missing a dict such as the end date for their university/education (bolded below). What mechanism would I use to have it return a default value (i.e “N/A”) instead of tripping up a “Key Error” for missing the dict? I apologize for such a basic question, I’m just starting out with Python / Django. I really appreciate the help!

def home(request):
    now = datetime.datetime.now()
    html = "<html><body>"
    token = oauth.Token(request.user.get_profile().oauth_token,request.user.get_profile().oauth_secret)
    client = oauth.Client(consumer,token)
    headers = {'x-li-format':'json'}
    url_list = ["redacted-URL","redacted-URL", "redacted-URL"]
for x in url_list:
    url = "http://api.linkedin.com/v1/people/url="+x+":(id,first-name,last-name,headline,industry,three-current-positions,**educations:(end-date,**degree,field-of-study,school-name))" 
        resp, content = client.request(url, "GET", headers=headers)
        profile = json.loads(content)
    html += profile['firstName'] + " " + profile['lastName'] + ": " + profile['headline'] + " | " + profile['industry'] + " | " + profile['threeCurrentPositions']['values'][0]['company']['name']+ " | " + profile['threeCurrentPositions']['values'][0]['title']+ " | " + profile['educations']['values'][0]['fieldOfStudy']+ " | " + profile['educations']['values'][0]['degree']+ " | " + profile['educations']['values'][0]['schoolName']+ " | " **+str(profile['educations']['values'][0]['endDate']['year'])** + "<p/>"
    return HttpResponse(html)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T13:13:01+00:00Added an answer on May 31, 2026 at 1:13 pm

    You can use dict.get(key, default) instead of dict[key] to specify a default value when doing a dictionary lookup.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The ruby gem for LinkedIn that I'm using is here: http://github.com/pengwynn/linkedin When calling LinkedIn::Client.new
Calling the ajax called URL works well without ajax eg. http://localhost/ci/controller/method/param_value . But using
Calling a .net SOAP1.1 web service from android using ksoap2 lib I met a
Calling a GUI app using [DllImport( advapi32.dll, EntryPoint = CreateProcessAsUser, SetLastError = true, CharSet
I am trying to display LinkedIn member profiles by having a user enter in
Calling : $.ajax({ type: POST, url: 'http://blahblah/cow.php', contentType: application/json, data: { 'guid': '111', 'score':
Calling TextRenderer.MeasureText as follows: TextRenderer.MeasureText(myControl.Text, myControl.Font); and comparing the result to the size of
Calling image = Image.open(data) image.thumbnail((36,36), Image.NEAREST) will maintain the aspect ratio. But I need
Calling Html.RenderPartial(~/Views/Payments/MyControl.ascx); from a view works if MyControl.ascx is a control that directly inherits
//calling class import javax.swing.JFrame; class jcheckkbox { public static void main(String args[]) { jRadio

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.