Python Forum

Full Version: Type error: dump() missing 1 required positional argument: fp
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, I am trying to create a json file that stores my users email for subscription purposes. I get an error that says, 'Type error: dump() missing 1 required positional'. Here is my code:

print('Welcome to the Urban ')

import json

import username

import favartist


def userfav():
    userfav = input('Please select your favorite artist: \n ')
    a = 'Yes' or 'yes'
    ab = 'No' or 'no'
    if userfav == 'Drake':
        subs = input('Would you like to subscribe to notifications for Drake?:')
        if subs == a:
            print('Thank you for subscribing')
        elif subs == ab:
            print('You ca subscribe later')
        else:
            print('Selection is invalid')
    elif userfav == 'J.Cole':
        subs = input('Would you like to subscribe to notifications for J.Cole?:')
        if subs == a:
            print('Thank you for subscribing')
        elif subs == ab:
            print('You ca subscribe later')
        else:
            print('Selection is invalid')

    elif userfav == 'Anderson Paak':
        subs = input('Would you like to subscribe to notifications for Drake?:')
        if subs == a:
            print('Thank you for subscribing')
            ussubem()
        elif subs == ab:
            print('You ca subscribe later')
        else:
            print('Selection is invalid')


userfav()

def ussubem():
    userfav = True
    a = True
    sub_e = input('Please enter your subscription email: \n ')
    em = sub_e
    return print('Thank you, will now receive regular emails about The Urban Macchiato to,' + sub_e)

ussubem()

with open('usersub.json', 'w+') as json_file:
    json.dump(ussubem)
To make it work,also for now remove stuff that don't make sense.
import json

def ussubem():
    sub_e = input('Please enter your subscription email: \n ')
    return f'Thank you, will now receive regular emails about The Urban Macchiato to {sub_e}'

email = ussubem()
with open('usersub.json', 'w') as json_file:
    json.dump(email, json_file)
When you do userfav = True it's overwrite function userfav() then all code is gone and it's only True.
To check a condition in function then something like this:
if 'email stuff' in userfav():
    # Write json
else:
    # Not okay,try again
Okay, I have gotten rid of some of the unnecessary code, but I am still receiving error messages. Here is my code:

 
print('Welcome to the Urban ')

import json

import username

import favartist



def userfav():
    userfav = input('Please select your favorite artist: \n ')
    a = 'Yes' or 'yes'
    ab = 'No' or 'no'
    if userfav == 'Drake':
        subs = input('Would you like to subscribe to notifications for Drake?:')
        if subs == a:
            print('Thank you for subscribing')
        elif subs == ab:
            print('You ca subscribe later')
        else:
            print('Selection is invalid')
    elif userfav == 'J.Cole':
        subs = input('Would you like to subscribe to notifications for J.Cole?:')
        if subs == a:
            print('Thank you for subscribing')
        elif subs == ab:
            print('You ca subscribe later')
        else:
            print('Selection is invalid')

    elif userfav == 'Anderson Paak':
        subs = input('Would you like to subscribe to notifications for Drake?:')
        if subs == a:
            print('Thank you for subscribing')
            ussubem()
        elif subs == ab:
            print('You can subscribe later')
def ussubem():
    a = True
    sub_e = input('Please enter your subscription email: \n ')
    return print('Thank you, will now receive regular emails about The Urban Macchiato to,' + sub_e)

userfav()
ussubem()

def writesub(ussubem):
    with open('usersub.json', 'w+') as f:
        json.dump(sub_em, f)

writesub(ussubem)