Python Forum
Type error: dump() missing 1 required positional argument: fp
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Type error: dump() missing 1 required positional argument: fp
#1
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)
Reply
#2
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
Reply
#3
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)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Wrong type error rowan_bradley 6 1,145 Aug-07-2023, 10:44 AM
Last Post: rowan_bradley
  Strange argument count error rowan_bradley 3 659 Aug-06-2023, 10:58 AM
Last Post: rowan_bradley
  Type Error: Unsupported Operand jhancock 2 1,068 Jul-22-2023, 11:33 PM
Last Post: jhancock
  i want to use type= as a function/method keyword argument Skaperen 9 1,775 Nov-06-2022, 04:28 AM
Last Post: Skaperen
  Error TypeError: output_type_handler() takes 2 positional arguments but 6 were given paulo79 1 1,858 Oct-17-2022, 06:29 PM
Last Post: paulo79
  "SUMIF" type query in Python (help required) BlainEillimatta 0 802 Oct-06-2022, 09:08 AM
Last Post: BlainEillimatta
  Error: _vhstack_dispatcher() takes 1 positional argument but 9 were given alexfrol86 3 5,717 May-09-2022, 12:49 PM
Last Post: deanhystad
  Python Anytree - Is not of type 'NodeMixin' error georgebijum 3 2,027 May-05-2022, 01:43 PM
Last Post: Gribouillis
  What is positional argument self? Frankduc 22 5,492 Mar-06-2022, 01:18 AM
Last Post: Frankduc
  TypeError: missing a required argument: 'y' gible 0 2,844 Dec-15-2021, 02:21 AM
Last Post: gible

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020