TypeError: x missing 1 required positional argument: y

rudehlabya

I am trying to import and call a function from my refactor file into my init file. However, when I attempt to call the function in one of the routes, I get this error in the terminal, "TypeError: show_state_locations() missing 1 required positional argument: 'test_code'"

Here is my code and how I am importing everything:

refactor

import requests
from privateinfo import key

def test_code(state, API_BASE_URL):
    url = f'https://covid-19-testing.github.io/locations/{state.lower()}/complete.json'
    res = requests.get(url)
    testing_data = res.json()
    latsLngs = {}
    for obj in testing_data:
          if obj["physical_address"]:

            for o in obj["physical_address"]:
                    addy = o["address_1"] 
                    city = o["city"]
                    phone = obj["phones"][0]["number"]

            location = f'{addy} {city}'
            res2 = requests.get(API_BASE_URL,
                                params={'key': key, 'location': location})

            location_coordinates = res2.json()
            lat = location_coordinates["results"][0]["locations"][0]["latLng"]["lat"]
            lng = location_coordinates["results"][0]["locations"][0]["latLng"]["lng"]
            latsLngs[location] = {'lat': lat, 'lng': lng, 'place': location, 'phone': phone}

init

from .refactor import test_code


@app.route('/location')
def show_state_locations(test_code):
    """Return selected state from drop down menu"""
    state = request.args.get('state')
    test_code(state, API_BASE_URL)

    return render_template('location.html', latsLngs=latsLngs)
C.Nivs

You are assuming that a name is persisted from one function call to its outer scope:

def f():
    x = 1

f()
print(x)
NameError: name x is not defined

You need to return the value and assign the name to x in the calling scope for this to work

def f():
    return 1

x = f()
x
1

Note that return x doesn't work either, because it's the value that's being returned, not the name:

def f():
    x = 1
    return x

f()
x
# NameError!

x = f()
x
1

The same is happening to latLng:

def test_code():
    latLng = {}

test_code()
latLng = latLng
#NameError!

Change it to

def test_code():
    latLng = {}
    ...
    return latLng

latLng = test_code()
latLng = latLng
# no error

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

TypeError: Missing 1 required positional argument: 'self'

From Dev

Pygame TypeError: missing 1 required positional argument:

From Dev

Pygame - TypeError: Missing 1 required positional argument

From Dev

TypeError: func1() missing 1 required positional argument: 'self'

From Dev

missing 1 required positional argument

From Dev

TypeError: overlaps() missing 3 required positional arguments: 'y1', 'x2', and 'y2'

From Dev

TypeError: missing 1 required positional argument: 'self' but the class is instanciated

From Dev

python smtp TypeError: sendmail() missing 1 required positional argument: 'msg'

From Dev

TypeError: get_params() missing 1 required positional argument: 'self'

From Dev

TypeError: classify() missing 1 required positional argument: 'featureset'

From Dev

TypeError: insert() missing 1 required positional argument: 'string'

From Dev

python TypeError: __new__() missing 1 required positional argument: 'namespace'

From Dev

Pandas DataFrame TypeError: quantile() missing 1 required positional argument: 'quantile'?

From Dev

TypeError: lemmatize() missing 1 required positional argument: 'word

From Dev

TypeError: __call__() missing 1 required positional argument: 'inputs'

From Dev

python decorator TypeError missing 1 required positional argument

From Dev

TypeError: <lambda>() missing 1 required positional argument: 'w'

From Dev

TypeError: on_message() missing 1 required positional argument: 'message'

From Dev

TypeError: delete() missing 1 required positional argument: 'indexPosition'

From Dev

tensorflow TypeError: ParseFromString() missing 1 required positional argument: 'serialized'

From Dev

TypeError: player_attack() missing 1 required positional argument: 'self'

From Dev

TypeError: cone() missing 1 required positional argument: 'height'

From Dev

TypeError on Python. Missing1 required positional argument

From Dev

TypeError: __init__() missing 1 required positional argument: 'id'

From Dev

TypeError: str() missing 1 required positional argument: 'self'

From Dev

TypeError: insert() missing 1 required positional argument: 'string'

From Dev

Python TypeError: set() missing 1 required positional argument: 'value'

From Dev

TypeError: askopenfilename() missing 1 required positional argument: 'root' In [ ]:

From Dev

TypeError: grid_configure() missing 1 required positional argument: 'self'

Related Related

  1. 1

    TypeError: Missing 1 required positional argument: 'self'

  2. 2

    Pygame TypeError: missing 1 required positional argument:

  3. 3

    Pygame - TypeError: Missing 1 required positional argument

  4. 4

    TypeError: func1() missing 1 required positional argument: 'self'

  5. 5

    missing 1 required positional argument

  6. 6

    TypeError: overlaps() missing 3 required positional arguments: 'y1', 'x2', and 'y2'

  7. 7

    TypeError: missing 1 required positional argument: 'self' but the class is instanciated

  8. 8

    python smtp TypeError: sendmail() missing 1 required positional argument: 'msg'

  9. 9

    TypeError: get_params() missing 1 required positional argument: 'self'

  10. 10

    TypeError: classify() missing 1 required positional argument: 'featureset'

  11. 11

    TypeError: insert() missing 1 required positional argument: 'string'

  12. 12

    python TypeError: __new__() missing 1 required positional argument: 'namespace'

  13. 13

    Pandas DataFrame TypeError: quantile() missing 1 required positional argument: 'quantile'?

  14. 14

    TypeError: lemmatize() missing 1 required positional argument: 'word

  15. 15

    TypeError: __call__() missing 1 required positional argument: 'inputs'

  16. 16

    python decorator TypeError missing 1 required positional argument

  17. 17

    TypeError: <lambda>() missing 1 required positional argument: 'w'

  18. 18

    TypeError: on_message() missing 1 required positional argument: 'message'

  19. 19

    TypeError: delete() missing 1 required positional argument: 'indexPosition'

  20. 20

    tensorflow TypeError: ParseFromString() missing 1 required positional argument: 'serialized'

  21. 21

    TypeError: player_attack() missing 1 required positional argument: 'self'

  22. 22

    TypeError: cone() missing 1 required positional argument: 'height'

  23. 23

    TypeError on Python. Missing1 required positional argument

  24. 24

    TypeError: __init__() missing 1 required positional argument: 'id'

  25. 25

    TypeError: str() missing 1 required positional argument: 'self'

  26. 26

    TypeError: insert() missing 1 required positional argument: 'string'

  27. 27

    Python TypeError: set() missing 1 required positional argument: 'value'

  28. 28

    TypeError: askopenfilename() missing 1 required positional argument: 'root' In [ ]:

  29. 29

    TypeError: grid_configure() missing 1 required positional argument: 'self'

HotTag

Archive