Bottom Page

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)

Quote
#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
Quote
#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)
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  creating hex dump modifying program ensoniq 3 176 Oct-14-2019, 08:21 AM
Last Post: Larz60+
  Syntax Error with Argument Parser aditya_man 1 200 Sep-30-2019, 01:21 PM
Last Post: ichabod801
  authentication required error with urlopen Ranjirock 2 196 Sep-11-2019, 01:01 PM
Last Post: Ranjirock
  Invalid argument error thrown. pyseeker 4 618 Sep-10-2019, 07:03 PM
Last Post: pyseeker
  Type Error: bad operand type for unary +: 'str' Psypher1 2 1,308 Aug-12-2019, 02:30 PM
Last Post: Psypher1
  catch input type error mcmxl22 5 293 Aug-11-2019, 07:33 AM
Last Post: wavic
  Missing required dependencies when using pyinstaller Ghonim 15 4,077 Jul-15-2019, 08:47 AM
Last Post: shubhthkr
  Type error when reading in different data types on an __init__ method Dylanmull 3 350 May-09-2019, 02:05 PM
Last Post: buran
  print python json dump onto multiple lines lhailey 1 1,069 May-05-2019, 03:24 PM
Last Post: Yoriz
  missing 1 required positional argument: psosmol 7 3,789 Apr-16-2019, 10:07 AM
Last Post: DeaD_EyE

Forum Jump:


Users browsing this thread: 1 Guest(s)